3

I want to take advantage of the sortableRows property of the jqGrid. How do I detect when a row has been moved. I have studied the documentation and looked for examples but haven't found much. I do believe it is something like

jQuery("#grid").sortableRows({connectWith:'#gird',
                              ondrop: function(){ alert("row moved") }});

but that does not work. I can move the rows, but don't seemed to have trapped the event. Is there something wrong with my syntax or my approach in general.

Basically, I need to know that the rows have been rearranged so I can be sure they get saved with their new order.

Thanks

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
DW.
  • 71
  • 1
  • 2
  • 3

3 Answers3

7

jqGrid uses the ui-sortable plugin to sort rows: http://jqueryui.com/demos/sortable/. In

jQuery("#grid").sortableRows( options )

"options" is the passed to the sortable plugin.

options = { update : function(e,ui){} }

is what you want.

Kevin
  • 71
  • 1
  • 1
4

Attach the sortstop event handler to your grid:

jQuery("#grid").bind('sortstop', function(event, ui) { alert("row moved") });

I did a quick test and that worked for me.

Mark
  • 5,499
  • 34
  • 29
0
jQuery('#'+grid_id).jqGrid('sortableRows', {
                    update: function (event, ui) {
                        var newOrder = $('#'+grid_id).jqGrid("getDataIDs");
                        //do whatever you want with new roworder
                        //please keep in mind this will give only page visible rows
                    }
                });
M.Hemant
  • 2,345
  • 1
  • 9
  • 14
  • Please explain why this answer, and how it differs from the existing answers. – Simon.S.A. Feb 12 '19 at 04:24
  • According to DW, the question needs to trap row movement event and want new row order so I give little more code here. there is nothing different with existing[Marks answer], I just give more detailing – M.Hemant Feb 12 '19 at 04:35