jqgrid get all grids column names

user590586 picture user590586 · Mar 29, 2011 · Viewed 34.7k times · Source

Is there a way to get all of the grid's column names?

Answer

Oleg picture Oleg · Mar 30, 2011

You can get the column names with

var columnNames = $("#list")[0].p.colNames;

or

var columnNames = $("#list").jqGrid('getGridParam','colNames');

The only small problem is that the array columnNames will contain up to three empty first elements in case of you use rownumbers:true, multiselect:true or subGrid:true parameters. This parameters to follow to inserting in the colModel additional columns with the names 'rn', 'cb' or 'subgrid'. So you can either just ignore the first empty elements of columnNames or look additionally in the colModel ($("#list")[0].p.colModel or $("#list").jqGrid('getGridParam','colModel')). The colModel and colNames arrays has the same length and the colModel[i].name can be used to examine whether colNames[i] is the name of "real" column or an additional column added because of the usage one from the tree above mention parameters.