ParamQuery grid support forum
General Category => Help for ParamQuery Grid (free version) => Topic started by: noctrona on February 13, 2014, 01:25:03 pm
-
Hi,
I know we can add/remove row dynamically. But I have a requirement to add/remove column in grid, so I want to know whether we can do it?
Thank you!
-
Add a new column object in colModel using push (if at end) or splice (if in middle)
colModel.push( { title: "yyy", dataIndx: "xxx", width : n } );
and call
$grid.pqGrid( "refreshDataFromDataModel" );
$grid.pqGrid ( "refresh" );
-
Add a new column object in colModel using push (if at end) or splice (if in middle)
colModel.push( { title: "yyy", dataIndx: "xxx", width : n } );
and call
$grid.pqGrid( "refreshDataFromDataModel" );
$grid.pqGrid ( "refresh" );
Hi,
Thanks for your response.
I try it on my page. But still have problem.
As I understanding, I need to get the all colModel array then I can push new column in it. Is that right?
I use the following code:
var colModel = $( ".selector" ).pqGrid( "option", "colModel" );
var title=colModel[0].title;
But when I get the "colModel" and try to get some attributes about this object, I will see the following error:
Cannot read property 'title' of undefined.
I'm sure I import "pqgrid.min.js" on my page.
So do you know why this happened? Do I make any mistake for these codes?
Thank you!
-
From the error it seems that your colModel is empty; you haven't added any column in it yet.
Just check the length of colModel before trying to access colModel[0]
http://jsfiddle.net/LAgZx/217/
-
From the error it seems that your colModel is empty; you haven't added any column in it yet.
Just check the length of colModel before trying to access colModel[0]
http://jsfiddle.net/LAgZx/217/
You are right. I check my code and found a stupid mistake. I didn't get colModel about my target, that's why colModel is empty.
Thank you!