Search code examples
dynamicgroup-byjqgrid

dynamic multiple grouptext in jqgrid


I have implemented multiple grouping in jqgrid which is dynamic(can be on 1 or many columns). And I want the grouptext to have a checkbox, column name and the value.

$("#Grid").jqGrid({
    ...
    grouping:true,
    groupingView:{
    ...
    grouptext:['<input type="checkbox" class="groupHeader"/> ColumnName: {0}']
})

This will give me grouptext in only one groupheader. But I can have grouping on several columns where the columnName is dynamic. I tried this which is not working:

var columnNames=['ABC','DEF','GHI'];
var grouptext1=['<input type="checkbox" class="groupHeader"/> columnNames: {0}'] 

$('#Grid').jqGrid('setGridParam',{grouptext:grouptext1})

I can change the grouptext1 according to my needs. But I need a way to bind it to the jqGrid.

How can that be done?


Solution

  • Note that you have a typo errr in your code. The JavaScript is case sensitive and you have write grouping text property not correct. It should be groupText instead of grouptext as you write.

    If you can see, the groupingGroupBy method has a second parameter - options. That is exactley what you need. This parameter is a grouping options. Having this you can set the groupText. in a case you want like this

    $("#grid").jqGrid('groupingGroupBy', 
        ['col1','col2'], 
        { 
            groupText : [ 'checkbox for col1', 'checkbox for col2']
            ...
        }
    );