Sean Anderson
Sean Anderson

Reputation: 29331

How to set groupColumnShow to false when no data has been loaded into jqGrid?

I have a grid which initializes with no data, but then loads with data after some user interaction. My grid also uses the 'Grouping' features such that:

ordersGrid.jqGrid({
    url: '',
    mtype: '',
    datatype: 'local',
    colNames: ['Order', 'Task #', 'Type', 'Status', 'Assignee', 'Current Location',
        'Dest Location', 'Change No', 'Net Patched', 'SAN Patched', 'Select'],
    colModel: [
        { name: 'Order', index: 'Order ID'},
        { name: 'Task #', index: 'Task #'},
        { name: 'Type', index: 'Type'},
        { name: 'Status', index: 'Status'},
        { name: 'Assignee', index: 'Assignee'},
        { name: 'Current Location', index: 'Current Location'},
        { name: 'Dest Location', index: 'Dest Location'},
        { name: 'Change No', index: 'Change No'},
        { name: 'Net Patched', index: 'Net Patched'},
        { name: 'SAN Patched', index: 'SAN Patched'},
        { name: 'Select', index: 'Select', width:'75px', classes: "SelectColumn",
            editable: true, edittype:'checkbox', editoptions: {value:"True:False"},
            formatter:"checkbox", formatoptions: {disabled: false}}
    ],
    gridview: true,
    height: 'auto',
    pager: ordersGridPager,
    viewrecords: true,
    grouping: false, //Set to true once data is loaded.
    groupingView: {
        groupField: ['Order'],
        groupColumnShow: [false]
    },
    loadError: function(error) {
        console.error(error);
    }
});

If I set the property 'grouping' to true during initialization of the grid I see the following error on the page:

Uncaught TypeError: Cannot read property 'stype' of undefined 

This error doesn't exist if there is data on the grid before setting grouping to true. If I leave grouping as false everything is fine.

The problem is that I do not want to see my 'Order' column even when there is no data. How can I achieve this?

Here's a JS Fiddle with the issue: http://jsfiddle.net/qrjZD/1/

Upvotes: 0

Views: 1060

Answers (1)

Oleg
Oleg

Reputation: 221997

The main problem which produced the error is the usage of index property in the Order column which value is not equal to the value of name property. In case of local grid (datatype: 'local') you should never do this.

The next problem is that you used name property which contains special characters: spaces and #. It is not recommended because the name property will be used to constructs id attributes of some elements of the grid.

See the fixed code here: http://jsfiddle.net/qrjZD/3/.

Upvotes: 1

Related Questions