jqgrid get all grids column names

2019-03-14 15:04发布

问题:

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

回答1:

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.