jqgrid-动态启用分组 [英] jqgrid - dynamically enabling grouping
问题描述
我能够通过jqgrid演示页面中的示例实现分组功能.但是我不想默认启用分组功能,但是在更改选择列表时,我想启用分组功能.我尝试了几种选择,但没有一个成功?有人可以在这里帮助我吗,可能是我缺少了一些东西.这是我的代码...
I was able to implement grouping feature from examples in the jqgrid demo page. But I don't want to enable grouping by default but on the change of a select list I would like to enable the grouping feature. I have tried several options but none of them were successful? Could some one please help me here, may be I am missing something. Here is my code...
$("#dynamicGrouping").change(function() {
var value = $(this).val();
if(value) {
if(value == '') {
$('#grid').jqGrid('groupingRemove', true);
} else {
$('#grid').jqGrid('setGridParam', { grouping:true });
$('#grid').jqGrid('groupingGroupBy', value);
$('#grid').trigger('reloadGrid');
}
}
});
我的网格定义:
jQuery(function() {
$('#grid').jqGrid({
.....
.....
grouping: false,
groupingView : {
groupField : ['field_name'],
groupColumnShow : [true],
groupText : ['<b>{0} - {1} Item(s)</b>'],
groupCollapse : false,
groupOrder: ['asc'],
groupDataSorted : true
},
.......
.......
});
});
推荐答案
我认为您在代码中犯了一些错误.您发布的代码似乎对我来说是正确的,但是您无需另外设置grouping:true
并触发reloadGrid
,因为groupingGroupBy
是您自动执行的.
I supposed that you made some error in the code. The code which you posted seem me correct, but you don't need to set grouping:true
and trigger reloadGrid
additionally because groupingGroupBy
do this you automatically.
演示演示了如何动态设置或删除分组.
The demo demonstrates setting or removing of grouping dynamically.
因此您可以使用
$("#dynamicGrouping").change(function () {
var groupingName = $(this).val();
if (groupingName) {
$('#grid').jqGrid('groupingGroupBy', groupingName);
} else {
$('#grid').jqGrid('groupingRemove');
}
});
或更高级的版本
$("#dynamicGrouping").change(function () {
var groupingName = $(this).val();
if (groupingName) {
$('#grid').jqGrid('groupingGroupBy', groupingName, {
groupOrder : ['desc'],
groupColumnShow: [false],
groupCollapse: true
});
} else {
$('#grid').jqGrid('groupingRemove');
}
});
更新:一切也都适用于JSON数据:请参见演示.
UPDATED: Everything works with JSON data too: see the demo.
更新2 :我又看了一次代码,发现在网格初始化时gridview
将设置为true
:请参阅行.如果您没有gridview: true
并最初使用grouping: false
,则将无法仅更改grouping: true
.您还必须从分组限制中设置其他参数.正确.
UPDATED 2: I looked in the code one more time and I found out that gridview
will set to true
at the initialization of grid: see the lines. If you don't have gridview: true
and use initially grouping: false
then you will be not able to change just grouping: true
. You have to set also other parameters from the grouping limitations correctly.
所以您必须自己限制规则:
So you have to hold the rules from limitations yourself:
scroll: false,
rownumbers: false,
treeGrid: false,
gridview: true,
由于性能更好,因此我建议始终使用gridview: true
.
By the way I recommend always use gridview: true
because of better performance.
这篇关于jqgrid-动态启用分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!