Search code examples
jqueryjqgridpagination

What is the effect of paging on jqgrid's getChangedCells method when using clientArray(clientside) for editing?


I am using jqgrid with clientArray option for editing;My grid is using paging; Will the jqgrid getChangedCells method return the correct changed rows even after changing pages several times with a possibility of data from the server having changed?- for example if new rows are available from the server that will now appear in my grid if I page back; Wont there be a rowId conflict - the new rowIds will be pointing to different rows from the ones before new data became available? I guess I could always order my server data by the autoincrementing primary key?..


Solution

  • found out today on experimenting; paging (server side) a jqgrid clears the result of getChangedCells; I had to create a utility function to store the getChangedCells array so that it persists across paging; Im doing this so I can submit all the changes separately In jqgrid options I have something like:

    ('#grid').jqgrid({
      ....
      cellEdit:true,
      cellSubmit:'clientArray',
      colModel: [ {...,editable:true,
                       dataInit:function(el){
                         el.autocomplete({...});
                       }...} ... ],
      afterSaveCell:function(){
                    $.retainChangesOnPaging();
                     }
      ....
    

    });

    and in the utility retainChangesOnPaging I have something like:

    (function(){
      var retainedChanges;
      retainedChanges = new Array();
      $.retainChangesOnPaging = function(){
        var changedCells = ('#grid').jqGrid('getChangedCells');
        // loop over changedCells array, removing duplicates if you want to...
          return  retainedChanges.push(/* this is inside the loop; push current value to array*/);
         ....
      }
       $.getRetainedChanges = function(){
         return retainedChanges;
       }
    })(jQuery);
    

    then when Im ready to submit all changes to server, I call $.getRetainedChanges Another question : is the way I used the retainChangesOnPaging correct? something seems wrong though the code works - can I make it better in any way? are my closures ok?