简体   繁体   English

jqgrid设置标签不是列名

[英]jqgrid set label NOT by column name

I want to change my grid columns labels, but I have to do it not by their names. 我想更改我的网格列标签,但我必须这样做,而不是他们的名字。 Is there a way to change the lable through the column position or through jsonmap? 有没有办法通过列位置或通过jsonmap更改标签? any other way? 任何其他方式?

Thanks In Advance. 提前致谢。

The answer from tpeczek are based on the documentation of jqGrid, but it's not more correct. tpeczek的答案是基于jqGrid的文档,但它并不正确。 After some changes in the code one can't use more column position as the parameter of setLabel method (see the source code ). 在代码中的一些更改之后,不能使用更多列位置作为setLabel方法的参数(请参阅源代码 )。 So you have to provide the name of the column. 所以你必须提供列的名称。 If you have only the position you can get colModel and get the name property of the corresponding element of array colModel : 如果您只有位置,则可以获取colModel并获取数组colModel的相应元素的name属性:

var iPos = 3, // the position of the column
    $grid = $("#gridId"),
    colModel = $grid.jqGrid("getGridParam", "colModel");

$grid.jqGrid("setLabel", colModel[iPos].name, "New Label");

I recommend you additionally to read the answer where I provide the code allows to set labels in the JSON input of grid. 我建议你另外阅读我提供的答案代码允许在网格的JSON输入中设置标签。 The demo demonstrate the approach. 该演示演示了该方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM