jQuery jqgrid 获取所有网格列名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5476068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 19:14:05  来源:igfitidea点击:

jqgrid get all grids column names

jqueryjquery-uijqgrid

提问by user590586

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

有没有办法获得所有网格的列名?

回答by Oleg

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 columnNameswill contain up to three empty first elements in case of you use rownumbers:true, multiselect:trueor subGrid:trueparameters. This parameters to follow to inserting in the colModeladditional columns with the names 'rn', 'cb'or 'subgrid'. So you can either just ignore the first empty elements of columnNamesor look additionally in the colModel($("#list")[0].p.colModelor $("#list").jqGrid('getGridParam','colModel')). The colModeland colNamesarrays has the same length and the colModel[i].namecan 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.

唯一的小问题是,columnNames如果您使用rownumbers:true,multiselect:truesubGrid:true参数,数组将包含最多三个空的第一个元素。此参数用于插入colModel具有名称'rn','cb'或的附加列中'subgrid'。因此,您可以忽略(或) 中的第一个空元素columnNames或另外查看。的和阵列具有相同的长度和所述可用于研究是否是“真实的”列或因为从上面提到的参数树中使用一个加入另外的列的名称。colModel$("#list")[0].p.colModel$("#list").jqGrid('getGridParam','colModel')colModelcolNamescolModel[i].namecolNames[i]