当我们在某些字段上分组行时,如何为JQGrid进行全局展开/折叠?

当我们在某些字段上分组行时,如何为JQGrid进行全局展开/折叠?

在扩展时,它应该扩展所有组,并且在折叠时应该折叠所有组。

您可以像设置任何其他默认参数一样设置jqGrid的groupingView参数的groupCollapse属性的默认值:

 $.extend($.jgrid.defaults, { groupingView: { groupCollapse: true } }); 

更新 :在评论中进一步解释之后,我可以想象,在某些情况下,如果扩展/折叠组中的任何组将被展开/折叠,它可以具有行为。

 var $grid = $("#list"), inOnClickGroup = false; $grid.jqGrid({ // ... other options grouping: true, onClickGroup: function (hid) { var idPrefix = this.id + "ghead_", id, i, l, groups = this.p.groupingView.sortnames[0]; if (!inOnClickGroup && hid.length > idPrefix.length && hid.substr(0, idPrefix.length) === idPrefix) { id = Number(hid.substr(idPrefix.length)); if (typeof (groups[id]) !== "undefined") { inOnClickGroup = true; // set to skip recursion for (i = 0, l = groups.length; i < l; i++) { if (i !== id) { $(this).jqGrid('groupingToggle', this.id + 'ghead_' + i); } } inOnClickGroup = false; } } } }); 

看演示 。

 $('#grid-expand-collapse').change(function () { var idPrefix = "MyGridghead_", index, length, tarspan; var groups = $(options.gridElement)[0].p.groupingView.sortnames[0]; if ($(this).is(':checked')) { for (index = 0, length = groups.length; index < length; index++) { tarspan = $("#MyGridghead_" + index + " span." + "tree-wrap-" + $(options.gridElement)[0].p.direction); if (!tarspan.hasClass($(options.gridElement)[0].p.groupingView.minusicon)) { $(options.gridElement).jqGrid('groupingToggle', 'MyGridghead_' + index); } } } else { for (index = 0, length = groups.length; index < length; index++) { tarspan = $("#MyGridghead_" + index + " span." + "tree-wrap-" + $(options.gridElement)[0].p.direction); if (tarspan.hasClass($(options.gridElement)[0].p.groupingView.minusicon)) { $(options.gridElement).jqGrid('groupingToggle', 'MyGridghead_' + index); } } } }); 
 $('#jqxGrid').jqxGrid({ groupsexpandedbydefault: true }); 

对我来说就像一个魅力( 来源 )。