jqGrid and Dynamic Grouping

无人久伴 提交于 2019-12-24 02:34:30

问题


I'm working on some dynamic grouping of my jqGrid, per the example posted at: http://www.trirand.com/blog/jqgrid/jqgrid.html (see the last section in the tree nav: 'Grouping: Dynamically Change Grouping'.

I can make my grid dynamically change the grouping IFF the grid initially has a grouping column. However, this is not the desired behaviour. Initially the grid needs to be ungrouped and allow the user to group items if they choose.

Code follows:

function onGroupByChanged(){
    var vl = $('#lstGroupBy').val();
    if(vl) {
        if(vl == "clear") {
            $("#refData").jqGrid('groupingRemove',true);
        } else {
            $("#refData").jqGrid('groupingGroupBy', vl);
            $("#refData").jqGrid('setGridParam', { grouping:true });
            $('#refData').trigger('reloadGrid');
        }
    }   
}

When I set the groupingGroupBy to the column name (contained in 'vl'), I receive this error in FireBug: can't convert null to object in jQuery min 1.4.2

I have even swapped the order of my calls to groupingGroupBy and setting grouping to true.

Anyone have an idea? I'm stuck and have spent about two hours on this already.

Thanks, Randall


回答1:


var GroupOption = new Object();
var groupField = [];

groupField.push(vl);

GroupOption.groupField = groupField;
GroupOption.groupColumnShow = true;
GroupOption.groupCollapse = false;
GroupOption.groupText = ['<strong> {0} - {1} Item(s)</strong>']

$("#refData").setGridParam({groupingView : GroupOption});
$("#refData").setGridParam({grouping : true});
$("#refData").trigger('reloadGrid');      



回答2:


Disregard.

In my grid's initial initialization, setting full options for the groupingView parameter, while setting grouping: false did the trick.

...
    grouping: grouping,
       groupingView : {
          groupField : [groupColParam],
          groupColumnShow : [true],
          groupText : ['<b>{0}</b>'],
          groupCollapse : true,
          groupOrder: ['asc'],
          groupSummary : [false]
       },
...


来源:https://stackoverflow.com/questions/5595828/jqgrid-and-dynamic-grouping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!