1

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? any other way?

Thanks In Advance.

user2046810
  • 393
  • 1
  • 8
  • 21
  • Look at [the answer](http://stackoverflow.com/a/16288582/315935). It provides code which shows how to change column labels dynamically. The text of labels in [the demo](http://www.ok-soft-gmbh.com/jqGrid/DynamicHeaderProperties.htm) are the part of JSON data returned from the server. – Oleg May 06 '13 at 11:13

1 Answers1

4

The answer from tpeczek are based on the documentation of jqGrid, but it's not more correct. After some changes in the code one can't use more column position as the parameter of setLabel method (see the source code). 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:

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. The demo demonstrate the approach.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798