是否存在使用 jqGrid 按需分组的解决方案?

发布于 2024-12-16 17:40:43 字数 131 浏览 6 评论 0原文

我想创建一个分组为 true 的 jqGrid,但只有第一个组展开,而其他组在展开该组时保持折叠状态,已折叠,我需要从服务器加载数据。

有人有解决方案吗?

PS:我需要使用分组,为什么用户可以选择其他列来动态分组。

I'm want to create a jqGrid with grouping:true, but only first group expanded and another groups stay collapsed when expand this group, was been collapsed, I need to load the data from the server.

Someone has a solution for that?

PS: I need use grouping, why the user can be select another columns to group on the fly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三人与歌 2024-12-23 17:40:43

要实现您的要求,您应该使用 groupCollapse: true 让所有组以折叠形式显示。例如

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

,然后根据 groupingToggle 网格被填满后。例如,您可以在 loadComplete 中使用以下代码:

loadComplete: function () {
    var $this = $(this), firstGroup = $this.find('tr.jqgroup:first');
    if (firstGroup.length > 0) {
        $this.jqGrid('groupingToggle', firstGroup[0].id);
    }
}

如果您提醒如何构造网格分组行的 id,您可以将代码简化为以下代码,

loadComplete: function () {
    $(this).jqGrid('groupingToggle', this.id + 'ghead_0');
}

请参阅 演示

要动态更改用于分组的列,您可以使用 groupingGroupBy 方法:

$("#list").jqGrid('groupingGroupBy', columnName);

例如 $("#list").jqGrid('groupingGroupBy', 'ship_via');。您应该明白,新的 groupField 仅在下次填充网格主体后才会使用。因此,如果您想在服务器上定义分组顺序并将其包含在服务器响应中,您应该在 beforeProcessing 内部调用 groupingGroupBy 方法,而不是在 loadComplete< 内部/代码>。

To implement your requirements you should use groupCollapse: true to have all groups displayed in collapsed form. For example like

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

and then expand the first group with respect of groupingToggle after the grid are filled. For example you can use the following code inside of loadComplete:

loadComplete: function () {
    var $this = $(this), firstGroup = $this.find('tr.jqgroup:first');
    if (firstGroup.length > 0) {
        $this.jqGrid('groupingToggle', firstGroup[0].id);
    }
}

If you remind the fact how the ids of the grouping rows of the grid will be constructed you can reduce the code to the following

loadComplete: function () {
    $(this).jqGrid('groupingToggle', this.id + 'ghead_0');
}

See the demo.

To change on the fly the column used for grouping you can use groupingGroupBy method:

$("#list").jqGrid('groupingGroupBy', columnName);

For example $("#list").jqGrid('groupingGroupBy', 'ship_via');. You should understand that the new groupField will be used only after the next filling of the grid body. So if you want to define on the server the grouping order and include it in the server response you should call groupingGroupBy method inside of beforeProcessing and not inside of loadComplete.

情魔剑神 2024-12-23 17:40:43

设置数据类型:'local'

然后

$("#list").setGridParam({datatype:'json'}).trigger('reloadGrid',[{page:1}]);

set your datatype:'local'

then

$("#list").setGridParam({datatype:'json'}).trigger('reloadGrid',[{page:1}]);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文