This is a migrated thread and some comments may be shown as answers.

What does options.error do?

3 Answers 451 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
Grant asked on 30 Aug 2019, 10:51 AM

Hi,

If i have the following read attribute in my datasource, what does 'options.error()' do?

read: function(options) {
  $.ajax({
    url: /*[[@{/accesslevels}]]*/"/planner/accesslevels",
      success: function (data) { options.success(data); }

      error: function (msg) { options.error(msg); }
    });
}

THanks, 

GRant

3 Answers, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 03 Sep 2019, 06:28 AM
Hi Grant,

In general, the Kendo UI DataSource performs an AJAX request to the server-side. In case the Read has been configured to be a function with a custom AJAX within, the developer would be able to override all of the options of the options supported by jQuery.ajax. Except the success and error callback functions which are used by the transport. 

That is why, within the success and error callbacks, you would have to manually invoke the callbacks of the outer function. Here is a code snippet with the relevant information enclosed in comments:

var dataSource = new kendo.data.DataSource({
  transport: {
    read: function(options) {
      // make JSONP request to https://demos.telerik.com/kendo-ui/service/products
      $.ajax({
        dataType: "jsonp", // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
        success: function(result) {
          // notify the data source that the request succeeded
          options.success(result);
        },
        error: function(result) {
          // notify the data source that the request failed
          options.error(result);
        }
      });
    }
  }
});

Let me know in case additional clarifications are needed.


Best regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
answered on 03 Sep 2019, 06:40 AM

Monring Tsvetomir, 

I understand the use of the options.error() callback. I just want to know what happens in the DS when its called. When you say "// notify the data source that the request failed". What does the DS do with that notification. does it remove a newly added row to a grid? Does it execute the datasource.error calllback? What actually happens when I call "options.error()"?

Thanks,
Grant

0
Tsvetomir
Telerik team
answered on 03 Sep 2019, 10:01 AM
Hi Grant,

When the error is added to the options, the data source would detect it and would trigger its Error event. The Error event is invoked only if there is an error returned from the server-side. 

If an error is encountered, it would not delete the existent changes, it would simply not save them. In the event handler, you would be able to handle the error, notify the user and optionally show a tooltip around the field that has caused the error. 

Furthermore, the data source has two collections. The one important in the current case is the collection with pristine data. It would not get updated unless the update/create/delete requests are successful. 


Best regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Data Source
Asked by
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
Answers by
Tsvetomir
Telerik team
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
Share this question
or