is there an example of using jqgrid's getChangedCells method to determine if data has changed?
I grepped getChangedCells in the downloadable demos for jqgrid, and could only find the function definition, not example usages of getChangedCells.
What I want to do is save the edits that a user's made if the user clicks on another row. But, I only want to submit the save if the row is dirty.
Thanks in advance, --Nate
Finally, I managed to bring a piece of code to detect what we want ;)
Hopefully any jqgrid gurus there (like Oleg), have enough time to review this code and improve it.
The example code will work for detect data changed in a grid with an editable field named "name". If you want to check for changed data in more columns, you have to add the variables
after_edit
andbefore_edit
asociated with that columns.To get the previous cell data inside the
onSelectRow
function, I don't used thegetCell
method because in the documentation says in red:By disgrace I could check that the documentation was right :(. However the
getCell
function works properly with the current cell data.And here is the code:
Using MVC4 and JQuery this is what I did
In the View
in the Model
The gridInitialised code is to handle changes to the search filter.
Dave
As Oleg mentioned 5 (wow) years ago - I used the saveRow function and passed the flag as
extraparam
.something like this, assuming your "model" or a hidden column
IsDirty
in my case:and then loop through the rows on Save click (external button in my case), something along the lines of:
In one of my projects I did the following: before editing the row I remember row data in global variable and after editing is done just check if row data was changed. Something like this (edit mode activated by double click):
var beforeEditData;
There are no safe dirty flag on the row. You can use the fact that at the beginning of row editing (at the start of the inline editing mode) the method editRow add
editable="1"
attribute to the grid row (<tr>
element). Later the methods saveRow and restoreRow changes the attribute value toeditable="0"
. So the rows of the current page which was at least once in the inline editing mode will have theeditable
attribute. If the id of the table element is "list" you can find the edited rows withThe ids of the elements of the set are the rowids of the rows.
If you use paging in the grid you should be careful and save the ids of the edited rows on the current page before the changing of the page. The onPaging event would help you here.
In my opinion the best and the most safe way to do what you need is to use
aftersavefunc
parameter of the editRow or saveRow methods (probably you use directly only editRow). Inside of youraftersavefunc
function you can save the id of the modified row in an array/map. This will solve your problem and will safe work.