在jqGrid上进行客户端排序后,如何突出显示最后选择的行? [英] How to highlight the last selected row after client-side sorting on jqGrid?
问题描述
我有一个基于jqGrid的应用程序,我在grid选项中使用了loadonce: true
,在colModel
中使用了sortable: true, sorttype: 'text
,以允许在数据网格上进行客户端排序.但是,我发现,一旦对数据网格重新排序,最后选择的行将不再突出显示.我的问题是,如何使选定的行在数据重新排序中突出显示?
I've a jqGrid-based application, and I use loadonce: true
in the grid option and sortable: true, sorttype: 'text
in the colModel
to allow client-side sorting on the data grid. However, I found that, once the data grid is re-sorted, the last selected row will no longer be highlighted. My question is, how to keep the selected row being highlighted across data resorting?
推荐答案
我为您准备了 selectionPreserver 在reloadGrid用法具有其他参数的情况下使用:$("#list").trigger("reloadGrid", [{current:true}]);
.有关详细信息,请参见答案.
I prepared for you the small demo which keeps the row selection. In the demo I rewrote the code of selectionPreserver used in case of reloadGrid usage having additional parameters: $("#list").trigger("reloadGrid", [{current:true}]);
. See the answer for details.
该演示程序将当前选择保存在onSortCol
事件处理程序中,并将其还原到loadComplete
中:
The demo saves the current selection inside of the onSortCol
event handler and restore it inside of the loadComplete
:
onSortCol: function () {
saveSelection.call(this);
},
loadComplete: function () {
restoreSelection.call(this);
}
如何看待用法非常简单,您可以将其集成到代码中. saveSelection
和restoreSelection
的实现如下:
How you see the usage is very simple and you can integrate it in your code. The implementation of the saveSelection
and restoreSelection
is the following:
var lastSelArrRow = [],
lastScrollLeft = 0,
lastSelRow = null,
saveSelection = function () {
var $grid = $(this);
lastSelRow = $grid.jqGrid('getGridParam', 'selrow');
lastSelArrRow = $grid.jqGrid('getGridParam', 'selrow');
lastSelArrRow = lastSelArrRow ? $.makeArray(lastSelArrRow) : null;
lastScrollLeft = this.grid.bDiv.scrollLeft;
},
restoreSelection = function () {
var p = this.p,
$grid = $(this);
p.selrow = null;
p.selarrrow = [];
if (p.multiselect && lastSelArrRow && lastSelArrRow.length > 0) {
for (i = 0; i < lastSelArrRow.length; i++) {
if (lastSelArrRow[i] !== lastSelRow) {
$grid.jqGrid("setSelection", lastSelArrRow[i], false);
}
}
lastSelArrRow = [];
}
if (lastSelRow) {
$grid.jqGrid("setSelection", lastSelRow, false);
lastSelRow = null;
}
this.grid.bDiv.scrollLeft = lastScrollLeft;
};
这篇关于在jqGrid上进行客户端排序后,如何突出显示最后选择的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!