jqGrid add new column
Asked Answered
L

4

15

I found that in jqGrid plugin for JQuery I can add rows dynamically, but can I do the same with columns? If there would be a simple table I'd prefer to do this manually by hands, but jqGrid stores table information in a lot of divs.

Lawgiver answered 20/11, 2010 at 9:31 Comment(2)
And where your grid will take data for this new column?Felic
@grizzzly8 it should be empty (the data fields are editable).Lawgiver
R
30

It is not possible to add a column to the jqGrid dynamically. You have to recreate the whole grid with colModel having one column more. If you use separate colNames, then the size of the array have to be increased too. You can use GridDestroy for example to destroy the existing grid. The usage of jQuery.Remove or jQuery.Empty instead is also possible.

UPDATED: It seems to me that GridUnload is better for your porpose. I created small demo which demonstrate how one can recreate a grid. To be able to use GridUnload or GridDestroy you have to verify that you include grid.custom.js in your project (if you use developer version of the jqGrid) or you have checked "Custom" "Additinal methods" on the jqGrid download page.

UPDATED 2: One can use addColumn method which can be downloaded from here (see jQuery.jqGrid.addColumn.js). The method is still in beta phase. One can find some demos which shows how to use the method here (see addColumnX.htm examples).

Rating answered 20/11, 2010 at 10:2 Comment(2)
Thanks, but I can't find how to use GridDestroy. Can you help me with a small example? jQuery("#list").jqGrid('GridDestroy'); says that the function is undefined (GridDestroy)Lawgiver
@Oleg, Thank you very much. Once again you saved my time on jqgrid. +1.Saragossa
C
4

just use

$("#gridid").jqGrid('GridUnload');

it will unload grid totally and will be ready to load again with new columns and data.

Concordance answered 10/6, 2011 at 14:59 Comment(1)
In the newer version this doesn't work anymore. Use this to unload the jqGrid: $.jgrid.gridUnload('#list');Undeceive
D
0

rownumbers: true, and rownumWidth:25(default)

Darreldarrell answered 27/12, 2012 at 5:58 Comment(0)
T
-1

You can simply set the new column model and reload the grid:

var newColModel = $("#myGrid").jqGrid("getGridParam", "colModel").concat({ /* new column attributes */ });
$("#myGrid").jqGrid("setGridParam", {colModel: newColModel}).trigger("reloadGrid");
Trill answered 24/9, 2012 at 18:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.