我只需要根据用户从选项列表中的选择动态地重命名 JQgrid 列.我该怎么做?
I just need to rename JQgrid column dynamically as per user selection from a list of options. How can I do that?
推荐答案根据jqGrid 文档,colNames 网格创建后无法更改.
According to the jqGrid Documentation, colNames cannot be changed after the grid is created.
但是,您可以通过使用多个列来模拟列名更改.然后,您可以隐藏所有这些,除了将向用户显示的单个.当用户选择另一个时,只需交换所选列.例如,如果有效列是 [A, B, C, D],您可能首先只显示 A.然后如果用户选择 C,隐藏 A 并显示 C.这种方法的主要缺点是您需要复制但是,许多列的相同数据.
However, you might be able to simulate a column name change by using several columns. Then you can hide all of them except a single one which will be shown to the user. When the user selects another, just swap in the selected column. For example, if valid columns are [A, B, C, D] you might start by only showing A. Then if the user chooses C, hide A and show C. The main disadvantage to this approach is that you will need to copy the same data to many columns, however.
更新
根据 Galichev 的回答,您可以使用 setLabel 方法重命名列标题.
Per Galichev's answer, you can use the setLabel method to rename a column header.
更多推荐
动态更改 JQgrid 列名
发布评论