Interest Ask! +1 from me.
The problem with sorting editable rows or cells is to access the contents of the editing cells. The current jqGrid code does not do this, so inside the click
event handler in the column headers there is a check to see if there is any edit line in the grid. If any edit line / line exists, the sort will stop without calling the onSortCol
.
Thus, only the second way of saving or restoring editable cells before sorting is possible. To implement this, there is one small problem. If one binds an additional click
event in the column headings, it will be called after the previous standard jqGrid handler. Therefore, you cannot save or cancel editing before the click event is processed. The problem can be solved in two ways: either you can call the sortData
function from a new event handler, or you can change the order of bindings to the click
event. The following code demonstrates a second approach:
$.each($grid[0].grid.headers, function () { var $th = $(this.el), i, l, clickHandler, clickHandlers = [], currentHandlers = $th.data('events'), clickBinding = currentHandlers.click; if ($.isArray(clickBinding)) { for (i = 0, l = clickBinding.length; i < l; i++) { clickHandler = clickBinding[i].handler; clickHandlers.push(clickHandler); $th.unbind('click', clickHandler); } } $th.click(function () { var p = $grid[0].p, savedRow = p.savedRow, j, len = savedRow.length; if (len > 0) {
where $grid
defined as var $grid = $("#list")
. You can see how it works on the next demo .
source share