Prevent ClientDataSource item remove if sync fails

3 posts, 1 answers
  1. Omar
    Omar avatar
    13 posts
    Member since:
    Oct 2016

    Posted 27 Nov 2016 Link to this post

    Hi, I'm using a ClientDataSource with a Grid to communicate with a webservice from client-side.

    The webservice returns a custom response for any request: {"ErrorMessage":(error message or null),"IsSuccessful":(boolean),"Result":[(result of request)]}.

    In the ClientDataSource I defined the schema as follows to check for server errors

    <Schema DataName="Result" ResponseType="JSON" ErrorsName="ErrorMessage">
      <Model ID="id">

    And this function to show the error:

    function dataSource_error(e) {
       console.log("Error", e);
       serverNotification.set_title("Server Error");

    My problem is that when I try to remove an item from the clientdatasource and I get a custom error,the item is still removed from the clientdatasource and the grid which is not an effect I'm looking for.

    For the clientdatasource remove/destroy I'm using a function:

    dataSource.transport.destroy = function (options) {
       console.log("Options-destroy", options);
          url: ("<%= WebApp.WebServiceHelper.BASE_WS_URL + WebApp.WebServiceHelper.WS_CLOSE %>"),
          dataType: "json",
          data: {
             username: sessionStorage["username"],
          success: function (result) {
            console.log("result-destroy:", result);
                            //if (result.IsSuccessful) {
                            //} else {
                            //    options.error(result);
            console.log("Options-destroy-success", options);
          error: function (result) {
            console.log("result1-destroy:", result);

    Before adding ErrorsName in the schema I was check the IsSuccessful on success and call options.error, in this case the clientDataSource remove the item but the grid did not rebind !

    On the same topic is it possible to check if IsSuccessful is false instead of ErrorMessage is null to generate an error and get the error message from ErrorMessage?

    In case of remove, the Result will be a boolean, can I also prevent the clientDataSource from removing an element if if Result is false?


  2. Omar
    Omar avatar
    13 posts
    Member since:
    Oct 2016

    Posted 29 Nov 2016 Link to this post

    Also similar thing occurs when updating an item, I loaded the page then disconnected my internet connection and tested update and remove. The error method is called but the item is either updated or removed.
  3. Answer
    Marin avatar
    1057 posts

    Posted 30 Nov 2016 Link to this post


    If an error occurs, you should rebind the grid (calling .rebind() method on the client-side). This should force the read method of the ClientDataSource to be executed again and the grid should display the correct records.

    Telerik by Progress
    Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
Back to Top