当我们在某些字段上对行进行分组时,我们如何为 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;
}
}
}
});
参见 the demo .
关于javascript - 当我们在某些字段上对行进行分组时,我们如何为 JQGrid 进行全局展开/折叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8369132/