Is there any direct way to sort the data on jqGrid
at client side with inline editing? It does not sort data when the row is editable even if the row header is clicked.
Grid can't be sort if some line is editing. I think that the reason of your question is a misunderstanding about how inline editing works and how sorting works.
At the beginning of editing the original data from the editing row will be saved in internal parameter savedRow
array. In any time the user can revert the current modifications back to original state or save the current values in the grid. If keys: true
option of inline editing is enabled then the user can use Esc or Enter keys to revert/save the changes of the current row. It is permitted that multiple rows could be in the same time in editing mode and the user could save some rows and some other revert.
The sorting of grid means rebuilding of full grid content applying of the current filter from internal postData
parameter. jqGrid supports multiple pages . Sorting of grid means always the sorting of optionally filtered over all data of the grid . After sorting if should be displayed only the current page based on the value of page
parameter.
To sort the grid which is in editing mode one would need to decide what should be done with currently editing rows. Neither discarding of current changes nor saving could be good solution in common case. Even if one would try first to save the current editing data (old state and current state) then sort the data and later start editing one more time it could not work in common case. It could be many problems of implementation such scenario
savedRow
array with old data could be wrong and the current editing data could be also wrong. So to sort grid which is in editing mode is not easy. The implementation way could depend on the project requirements. Because of described above problems (and many other which I didn't mention) jqGrid just test whether internal savedRow
array (used to save old state of row before editing started) is empty or not. If the savedRow
array is not empty then there are some row or cell (in case of sell editing mode) which is editing now. In the case any click on the corresponding column header will be ignored and no sorting is done.
I had this same problem --not being able to sort if any row is in edit mode. In my case it didn't matter what the state of the user edits were. My grid is clientSide and there is a save button on the page the user's clicks to submit the changes.
I did some digging around and found a solution that works for me. I hope it helps others. Basically what I did was reorder the click events on the column headings so that mine was first. Then in my click event I call saveRows.
Here is a piece of code I got from another thread here about reordering events :
$.fn.bindUp = function(name, fn) {
// bind as you normally would
// don't want to miss out on any jQuery magic
this.on(name, fn);
// Thanks to a comment by @Martin, adding support for
// namespaced events too.
this.each(function() {
var handlers = $._data(this, 'events')[name.split('.')[0]];
// take out the handler we just inserted from the end
var handler = handlers.pop();
// move it at the beginning
handlers.splice(0, 0, handler);
});
};
Then in my code I add a handler to save the rows:
$("th.ui-th-column", $("#pacPaymenReviewGridNEW")[0].grid.hDiv).bindUp('click', function(e) {
var $th = $(e.currentTarget).closest("th");
if ($th.length > 0) {
pacTransferFundMaint.saveRowsById('#pacPaymenReviewGridNEW');
}
});
After research, I found the following algorithm:
saveRow
when this event occurs Sort grid data with that header in ascending or descending order. like
$('#dataGrid').jqGrid('setGridParam', ({ data: list, sortname: columnHeader, sortorder: 'asc',rowNum: list.length })).trigger('reloadGrid');
Make the selected row editable again. editRow
can be used for this.
Note: Steps 2 to 5 should be executed in event at steps 1 (header click event)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.