Reputation: 777
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
Upvotes: 0
Views: 5345
Reputation: 222017
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.
Upvotes: 2