gpt4 book ai didi

javascript - jqGrid 问题分组 - 每次更改排序时都会附加重复的行

转载 作者:行者123 更新时间:2023-11-30 06:38:48 24 4
gpt4 key购买 nike

我正在使用 jqGrid 并将分组添加到我的一个网格中。未启用分组时一切正常,但是一旦我添加:

grouping: true,
groupingView: { groupField: ['ProjName'], groupDataSorted: true }

我开始遇到一些奇怪的行为。当我单击其中一个列标题以更改排序顺序时,并没有清除网格中的现有行,而是将新行附加到网格的末尾,所有组都被复制。

换句话说,当页面第一次绘制时,我看到了这个:

enter image description here

然后,我点击一个排序标题,我得到了这个:

enter image description here

我的初始化代码如下:

var gridMyTasks = $('#gridMyTasks').jqGrid({
jsonReader: { root: 'rows', repeatitems: false, id: 'ID' },
datatype: 'json',
colNames: ['Task ID', 'Task Name', 'Project Name', 'Task Stage', 'Doc Type', 'Due Date'],
colModel: [
{ name: 'ShortCode', width: 70, jsonmap: 'ShortCode' },
{ name: 'TaskName', width: 200, jsonmap: 'TaskName', formatter: 'fmtTaskName' },
{ name: 'ProjName', width: 200, jsonmap: 'ProjName', formatter: 'fmtName' },
{ name: 'TaskStage', width: 100, jsonmap: 'TaskStage' },
{ name: 'DocType', width: 130, jsonmap: 'DocType' },
{ name: 'DueDate', width: 70, jsonmap: 'DueDate' }
],
rowNum: 0,
height: 'auto',
autowidth: true,
forceFit: true,
multiselect: false,
caption: '',
altclass: 'zebra',
altRows: true,
hoverrows: false,
gridview: true,
grouping: true,
groupingView: { groupField: ['ProjName'], groupDataSorted: true }
});

我的加载程序代码(在排序时再次调用)如下所示:

loader(limit, curSort, curDir, function (results) {
grid[0].addJSONData({ rows: results });
$('body').hideLoading();
link.html(expanded ? 'Show less...' : 'Show all...');
},
null);

(loader 是对服务器的 AJAX 调用)- 我在想也许我需要做一些事情来清除所有现有的行?但是,为什么在我启用分组之前它工作得很好?

最佳答案

我想通了。我有以下代码:

grid.setGridParam({
onSortCol: function (index, iCol, sortorder) {
wait();
curSort = index;
curDir = (sortorder == 'desc');
loadGrid(expanded ? null : 15);
return 'stop'; // <--- Problem
}
});

当我注释掉 return 'stop' 时,问题就消失了。我不完全确定我为什么要开始这个,我想我试图禁用任何类型的内置排序。

关于javascript - jqGrid 问题分组 - 每次更改排序时都会附加重复的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12940664/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com