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

How to send only the changed fields to the server (during update) in Kendo UI Grid batch save

4 Answers 1209 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bharani
Top achievements
Rank 1
Bharani asked on 12 Mar 2013, 10:07 AM
Team, 

I would like to send only the changed fields from Kendo grid control to the server during the Update. By default Kendo is sending the entire record to the server even if one field is changed in that record. I would like to send only the updated fields rather than all fields.

How can i do it ?

Also, i would like to fire the update from an external button rather than the toolbar Save button. How to do it ?

Regards,
Bharani 

4 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 13 Mar 2013, 06:17 PM
Hi Bharani,

Thank you for getting in touch with us. Regarding your questions:
  1. I am afraid that what you would like to achieve is not supported. By design the DataSource tracks changes on record level, the exact field that was changed is not remembered. Moreover, if you send only the value of a single field, how would the server recognize which DataBase entry to update?

  2. To achieve that you can use saveChanges method of the Grid or sync method of its DataSource.

I hope this information will help.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Bharani
Top achievements
Rank 1
answered on 14 Mar 2013, 01:53 PM
Thanks for the answer. 

I want to send all my changes to the server during the batch save. I don't want to use the option of "update" on the transport object. How can i send all the changes without using the update url option ?

I would like to post all these changes to the Update Url myself on the external button click. Please let me know how to acheive this.
0
Alexander Valchev
Telerik team
answered on 18 Mar 2013, 09:20 AM
Hello Bharani,

To achieve that you can loop through the Grid's DataSource data array and search for models with dirty flag set to true. 
var dataSource = $("#grid").data("kendoGrid").dataSource,
    data = dataSource.data(),
    changedModels = [];
 
if(dataSource.hasChanges) {
    for(var i = 0; i < data.length; i++) {
        if(data[i].dirty) { changedModels.push(data[i].toJSON()) }
    }
}

This will let you submit the changedModels array via custom Ajax request.

I would like to remind you that by submitting the changes via separate Ajax request, the DataSource will not update. It is recommended to refresh the data, after custom update is finished. 

On a side note, the DataSource allows the developer to define custom transport function. For more information please see the corresponding documentation:

I hope this will help.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
1
horo
Top achievements
Rank 1
answered on 03 May 2013, 09:21 AM
Just a minor addition:

if (dataSource.hasChanges) is always true... as hasChanges is a javascript function not a property. Note it could be a property but it is not actually.

The 'if (dataSource.hasChanges())' works as it is the _return_ value of the function. I know this left () are  'evident' for a javascript guru, but takes hours to figure out for a javascript newbie. 

Regards
Horo
Tags
Grid
Asked by
Bharani
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Bharani
Top achievements
Rank 1
horo
Top achievements
Rank 1
Share this question
or