問題描述
當(dāng)我們在某個(gè)字段上分組行時(shí),如何為 JQGrid 進(jìn)行全局展開/折疊?
How can we have global Expand/Collapse for JQGrid when we have rows grouped on some field?
展開時(shí),應(yīng)展開所有組,折疊時(shí)應(yīng)折疊所有組.
On expanding, it should expand all groups and on collapsing all groups should be collapsed.
推薦答案
同樣的方法可以設(shè)置jqGrid的groupingView
參數(shù)的groupCollapse
屬性的默認(rèn)值就像您設(shè)置任何其他默認(rèn)參數(shù)一樣:
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
}
});
已更新:在評論中進(jìn)行了額外解釋后,我可以想象在某些情況下,當(dāng) 所有 組從組將被展開/折疊.
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;
}
}
}
});
參見演示.
這篇關(guān)于當(dāng)我們在某個(gè)字段上分組行時(shí),我們?nèi)绾螢?JQGrid 進(jìn)行全局展開/折疊?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!