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

Need ideas to ignore/reject response on UPDATE which doesn't match model

3 Answers 133 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 02 May 2017, 08:41 PM

An existing MSSQL Stored Procedure that updates records in the current application I'm building a new version of returns a totally different set of fields which then try to populate the grid the Datasource is bound to.

My current solution is to call this.read() on the Datasource sync event which usually handles it well enough but there are instances where is a hiccup in the process (e.g., network or page rendering) results in the grid showing various mismatched column values, if only briefly.

One possibility I thought of was to use schema.parse and if it sees one of the fields only returned by the UPDATE call then null the whole response, hopefully preventing the grid from trying to populate with the mismatched data.

Any other ideas? Am I overlooking a simple & elegant solution?

3 Answers, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 04 May 2017, 05:54 PM
Hi Scott,

As far as I understand the scenario, the Kendo UI Grid columns are autogenerated.

I believe that the best way to do that is to perform a check if the data is valid/without errors, then obtain one of its dataItems and build the schema and columns. A similar approach is shown in the below how to:

http://docs.telerik.com/kendo-ui/controls/data-management/grid/how-to/various/create-with-dynamic-columns-and-data-types 

Let me know what you think.

Regards,
Alex Hajigeorgieva
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
0
Scott
Top achievements
Rank 1
answered on 05 May 2017, 03:03 PM

The columns are not autogenerated. The grid has set columns and and the datasource has a set model that matches initial GET response.

The issue is, on dataSource.sync(), the UPDATE response is a different set of fields and unnecessary, so I want to ignore it altogether.

What I'm wondering is if I overlooked a feature in Kendo's Datasource to handle a that case simply.

Something like transport.update: { ignoreResponse: true } or sync: function (e) { if (e.transport.type === 'update') { return false; }

0
Alex Hajigeorgieva
Telerik team
answered on 09 May 2017, 04:10 PM
Hi Scott,

If you wish to discard the Kendo UI Data Source transport update result,  you could call the success of the update with the data which you wish to show.

e.g:

var dataSource = new kendo.data.DataSource({
  transport: {
    update: function(options) {
      $.ajax({
        url: "http://someurl.com/api/update",
        success: function(result) {
          // swap the response, instead of result, pass another array
          var data = [1,2,3];
          options.success(data);
        },
      });
    }
  }
});


If you wish to modify the response, you could use the data source schema parse function or its requestEnd event which will give you the type of request in its event data. 

Kind Regards,
Alex Hajigeorgieva
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
Tags
Data Source
Asked by
Scott
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Scott
Top achievements
Rank 1
Share this question
or