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

Modifying the parameters passed to remote service for Kendo UI grid datasource

1 Answer 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 16 Nov 2018, 02:44 PM

Hi,

I have Kendo Grid using JQuery which has datasource assigned in one of the javascript function using new instance of kendo.data.DataSource(). First time when datasource is created/assigned there are several parameters passed in transport: read: data. One of the parameters is flag which indicates if item should be saved. First time it's assigned to true to save the item in database. I do have all sorts options for grid inside the Kendo DropDownList. Inside the change event of those sort options I do sort on the grid using following code. But the problem is my item save flag remains true so when I do sort it also keep saving item in database creating duplicate entries. So wondering how can I change that item save flag before doing sort? 

 var grid = $("#GridId").data("kendoGrid");
 grid.dataSource.sort({ field: arr[0], dir: arr[1] });

 

Thanks!

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 20 Nov 2018, 08:28 AM
Hi Alex,

A possible solution is to pass a handler to the dataSource.transport.read.data configuration and add a condition for the additional parameters.

e.g.

// add a global flag which indicates whether the additional parameters should be sent
 
  var flag = true;
 
// data handler
 
      data: function(e) {
          if(flag){
            return {additional:1}
          }
      }
 
// sort logic
 
   flag = false; // set flag to false to avoid sending the additional params
   var grid = $("#GridId").data("kendoGrid");
   grid.dataSource.sort({ field: arr[0], dir: arr[1] });
   flag = true; // reset flag in case it is necessary to send parameters again


Regards,
Georgi
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
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or