問題描述
當我們在某個字段上分組行時,如何為 JQGrid 進行全局展開/折疊?
How can we have global Expand/Collapse for JQGrid when we have rows grouped on some field?
展開時,應展開所有組,折疊時應折疊所有組.
On expanding, it should expand all groups and on collapsing all groups should be collapsed.
推薦答案
同樣的方法可以設置jqGrid的groupingView
參數的groupCollapse
屬性的默認值就像您設置任何其他默認參數一樣:
You can set default value of the groupCollapse
property of the groupingView
parameter of jqGrid in the same way like you set any other default parameter:
$.extend($.jgrid.defaults, {
groupingView: {
groupCollapse: true
}
});
已更新:在評論中進行了額外解釋后,我可以想象在某些情況下,當 所有 組從組將被展開/折疊.
UPDATED: After additional explanation in the comments I can me imagine that in some cases it can has the behavior when all groups will be expanded/collapsed if any from the groups will be expanded/collapsed.
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;
}
}
}
});
參見演示.
這篇關于當我們在某個字段上分組行時,我們如何為 JQGrid 進行全局展開/折疊?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!