我有一个函数在jqgrid中向下移动一行,并保持选中该行。向上移动一行时,相同的功能可以正常工作。移动该行,但重新加载时未选中该行。
.navButtonAdd("#" + gridFieldsPagerID, {
title: "Move down",
caption: "",
buttonicon: "ui-icon-arrow-1-s",
position: "last",
onClickButton: function () {
var currentGridFieldIndex = $('#gridFields-grid').jqGrid('getGridParam', 'selrow');
if (currentGridFieldIndex === null) {
return;
}
var selectedGridField = $('#gridFields-grid').jqGrid('getLocalRow', currentGridFieldIndex);
var selectedGrid = $("#grid-grid").jqGrid('getLocalRow', row_id);
var recordCount = $('#gridFields-grid').jqGrid('getGridParam', 'reccount');
if (currentGridFieldIndex <= recordCount) {
MoveGridField(selectedGrid.name, selectedGridField.property, "down");
$('#gridFields-grid')
.jqGrid('setGridParam', {
data: GetGridFieldData(gridName)
})
.trigger('reloadGrid');
// The move up with -1 works as expected.
$('#gridFields-grid').jqGrid('setSelection', currentGridFieldIndex + 1);
}
}
})
编辑: 这是MoveGridField:
MoveGridField = function (gridName, propertyName, direction) {
var gridIndex = findIndexByKeyValue(this._grids, "name", gridName);
var fieldList = this._grids[gridIndex].fields;
moveField.call(this, fieldList, propertyName, direction);
},
和moveField:
moveField = function (fieldList, propertyName, direction) {
var index = findIndexByKeyValue(fieldList, 'property', propertyName);
if (direction == "up") {
if (index != 0) {
Swap(fieldList, index, index - 1);
return;
}
}
if (direction == "down") {
if (index != fieldList.length - 1) {
Swap(fieldList, index, index + 1);
return;
}
}
}