所以,我有一个运行良好的 jqGrid 工具。我正在显示一些数据行,当添加新数据时——网格会根据需要刷新。
但是,如果我尝试从网格中删除一行 - 它不会清除丢失的行!添加新行没问题,但删除会留下数据和错误的网格显示。
如果我先调用“clearGridData”,我会看到数据已适当清理。但是,如果我调用 clearGridData - 我会丢失我的选择/页面!
http://jsfiddle.net/yNw3C/1766/
var data = [[48803, "DSK1", "", "02200220", "OPEN"], [48769, "APPR", "", "77733337", "ENTERED"]];
$("#grid").jqGrid({
datatype: "local",
height: 250,
colNames: ['Inv No', 'Thingy', 'Blank', 'Number', 'Status'],
colModel: [{
name: 'id',
index: 'id',
width: 60,
sorttype: "int"},
{
name: 'thingy',
index: 'thingy',
width: 90,
sorttype: "date"},
{
name: 'blank',
index: 'blank',
width: 30},
{
name: 'number',
index: 'number',
width: 80,
sorttype: "float"},
{
name: 'status',
index: 'status',
width: 80,
sorttype: "float"}
],
caption: "Stack Overflow Example"
});
var names = ["id", "thingy", "blank", "number", "status"];
var mydata = [];
for (var i = 0; i < data.length; i++) {
mydata[i] = {};
for (var j = 0; j < data[i].length; j++) {
mydata[i][names[j]] = data[i][j];
}
}
for (var i = 0; i <= mydata.length; i++) {
$("#grid").jqGrid('addRowData', i + 1, mydata[i]);
}
$('#UpdateGridButton').click(function(){
mydata[0].status = "CLOSED";
delete mydata[1];
//If I add this -- I can refresh grid data properly, but I lose my selection.
//$('#grid').clearGridData();
$("#grid").jqGrid('setGridParam', { data: mydata});
$("#grid").trigger('reloadGrid', [{current: true}]);
});
jqGrid 是否支持两全其美?还是我需要编写自定义逻辑?