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