jqGrid setting colModels and colNames dynamically

Is it really necessary to unload $(“#myGrid”).jqGrid(‘GridUnload’); if you want to set again its colModels and colNames? Or should i say is it the only way to implement a dynamic columns of jqGrid? Although I’ve tried that one and it worked. But I also tried the setGridParam of jqGrid but it wont work when i put colModels/colNames.

This is what i did aside from unloading

    $.ajax({
            url     : url, //url the returns formatted colModels/colNames and other data
            data    : data, 
            async   : false,
            success : function(data){
            $("#myGrid").setGridParam({
                url : "xx/xxx/xx.json",
                page : 1,
                postData : {
               .
               .
               .
                },
                colNames : data.returnedColNames,
                colModel : data.returnedColModels,
                rowNum : 50,
                pager: '#myGridPager',
            }).trigger("reloadGrid");

            }
        });

But i get and error like Uncaught TypeError: Cannot read property ‘formatter’ of undefined

Any ideas on this approach? Thanks in advance



what are colnames and colmodel in jqgrid

Can you explain what are these colnames and colmodel in jqgrid ? Where are getting used ? defining columns , then …how these 2 colnames / colmodels are inter related and all ?? and can please point

Jqgrid with dynamic colNames?

Scripts: $.ajax({ url: ‘/Widget/GetTestData’, type: ‘POST’, data: {}, success: function (result) { var colModels = result.Json.colModels; var colNames = result.Json.colNames; var data = result.Json.da

Jqgrid and Data send error

I have this code.. var _codSelected=; $(#list).jqGrid({ url: ‘/modulos/mantenimiento/Proveedores.ashx’, datatype: ‘xml’, mtype: ‘GET’, colNames: [‘Codigo’ //Some more colnames and colmodels] colMo

jqGrid – setting caption dynamically

I have the caption parameter set in the jqGrid definition. I want to know if there’s a way to set it dynamically depending on the class attribute of the table element to which the jqGrid plugin is att

Setting jqGrid RowNum dynamically

I am facing an issue when using jqGrids. I have a jqGrid whose rowNum is set to 10. I have this in my JavaScript code: rowNum: 10, height: 160, width: 742, shrinkToFit: false, sortname: ‘CreditRequest

JQgrid: set dynamically format cell with cellattr and with dynamic number column

I first need to build dynamically the columns of grid, so I do: success: function(data){ var colnames = data.colnames; var colmodel = data.colmodel; $(#list).jqGrid({ … colNames: colnames, colMode

jQgrid tableToGrid() is ignoring colModel and ColNames in options

I was going through the documentation and source code of jqGrid 4.3.1 when it comes for the tableToGrid() function and I found that the ColModel and ColNames are ignored when included in the options o

jqGrid and dynamic column binding

How to bind jqGrid dynamically?. The columns are not available at design time but will only be available only at runtime. In the current jqGrid design the colmodels and other properties needs to be pr

jqGrid reloadGrid and refresh new colModel and colNames

I’m trying to reload a jqGrid with new rows, colNames and colModel. The row data seems to load fine but the columns don’t seem to be refreshed. I’ve tried using GridUnload and GridDestroy but I end up

Length of Colnames <> Colmodel issue JQGrid

Am trying to load Columns to JQGrid Dynamically using Ajax calls as mentioned here jqGrid and dynamic column binding i just did a sample with 1 column. My Column name JSON Data:[Airport] which wor

Answers

jqGrid creates some column structures during creating of the grid. If one created the grid once one can’t change the number of columns for example. On the other side you can makes some unneeded columns hidden. Setting of colModel will not change the column headers. On the other side you can use setLabel method to change column headers dynamically. The most values of colModel can be changes. The main restriction is: the number of columns should be the same. Another restriction: you should not change the value of name property of columns because the property will be used to generates ids of column headers. If you use repeatitems: false style of data then you can dynamically set jsonmap or xmlmap property of columns holding name property unchanges. Changing of width property by setGridParam will not change the width of existing columns. On the other side you can use setColWidth method which I suggested in the answer and which you can download from here. So you can creates grid with large enough number of columns and set the other columns as hidden.

The answer provides 90% of solution which you asked. I modifies colModel inside of beforeProcessing. Other answer contains short description of the solution which you need.