lordkain
lordkain

Reputation: 3109

save only when data is changed jqgrid.saveRow

I am using inline edit and want to call jqgrid.saveRow (even if nothing changed). If the data is not changed then there must not be call to the server to update.

how to skip sending data to the server if during inline editing no data in the row are changed?

Upvotes: 0

Views: 1163

Answers (1)

Oleg
Oleg

Reputation: 222007

jqGrid makes internally jQuery.ajax request to send the data to the server. You can use ajaxRowOptions option to make additional customization of the options used by jQuery.ajax. For example you can define beforeSend callback (see the documentation of jQuery.ajax for details). The callback will be called before sending the data. It's important that one can cancel the ajax request by returning false from the callback. The answer provide simple code which demonstrates how beforeSend callback can be defined.

To verify whether the data are changed or not during editing you can use internal jqGrid option savedRow (.getGridParam("savedRow") get the data). The option hold array of rows because jqGrid allows to call editRow for multipla strings at the same time. Every item of savedRow array have additional property id which you can use to find the item which will be currently saved.

So you can compare the data prepared to send to the server with the data saved in savedRow. You can do this inside of beforeSend callback. If you find out that the data are not changed the callback can return false to skip sending of the data to the server.

Upvotes: 3

Related Questions