tags:

views:

163

answers:

2

I have to edit a row in Jqgrid. When I try to select any row it is getting saved even when I not do any changes in that row. I need to select a row and It should save only when I do any changes. Can anyone help me for this issue. Below is the code.

 //for inline edit
 $('#PayorList').setGridParam({
     onSelectRow: function(id){
        if(id && id != lastSel){                             
          //save changes in row 
          //$('#PayorList').restoreRow(lastsel);
            $('#PayorList').saveRow(lastSel, succesfunc,'','',aftersavefunc ); 
             lastSel=id; 
            }
            //trigger inline edit for row
            $('#PayorList').editRow(id, true,oneditfunc, succesfunc,'','',aftersavefunc); 
           }
          });
A: 

There is no easy way around this problem using the API. You could use getRowData to inspect the edited row to determine if anything changed, however since the row will still be in the edited state at that point, you will have to parse raw HTML to get at the values - you cannot get at them directly using that method. But if you use this technique to determine if a row's data has not changed, you can then just call restoreRow to undo the change.

Alternatively you could just have saveRow execute anyway - you did not really say what kind of problem it was causing for you. If there is a real issue, can you be more specific?

Justin Ethier
A: 

I use ondblClickRow to switch jqGrid in inline edit mode. The modifications will be saved if the user press "enter" key or canceled on "esc" key. Probably it is the way which you would also like. See http://stackoverflow.com/questions/2863874/jqgrid-edit-only-certain-rows-for-an-editable-column/2866685#2866685 for an example.

Oleg