jqgrid get all grids column names

35,934

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.

Share:
35,934
user590586
Author by

user590586

Updated on July 09, 2022

Comments

  • user590586
    user590586 almost 2 years

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

  • Oleg
    Oleg over 11 years
    @FastTrack: You are welcome! I am glad to know that I could help you.
  • mrshickadance
    mrshickadance over 9 years
    I am using this function and splice the columnNames to get rid of the first checkbox column. It seems to affect the actual grids colNames though...any ideas why? I posted a question here about it - stackoverflow.com/questions/25558700/…
  • Harshit
    Harshit over 8 years
    @Oleg would this give the updated column order in case the user has reordered the columns? and would same be true for getting colModel ?
  • Oleg
    Oleg over 8 years
    @Harshit: Yes. getGridParam can be used to get internal parameters of jqGrid. If the columns will be reordered then the colNames array and colModel will be reordered too. Thus it's save to use .jqGrid("getGridParam", "colNames") and .jqGrid("getGridParam", "colModel"). You will get the reference to internal array with the information about the current columns.