JQGrid Header Header and Column Name

I have a JQGrid with two columns where I get to the server and get some data, then I will combine some rows based on filters on the server and want to set this as a signature, and also want to change the column names based on these filters. Is there any way to set the headers and column names based on the ActionResult from the server?

+6
source share
1 answer

I find your interest interesting.

We can start with a simple grid:

$("#list").jqGrid({ url: 'ColumnNamesAndTitelFromServer.json', datatype: 'json', loadonce: true, colNames: ['Name', 'Email'], colModel: [ {name: 'name', width: 100}, {name: 'email', width: 150} ], rowNum: 5, rowList: [5, 10, 20], pager: '#pager', gridview: true, rownumbers: true, sortname: 'name', sortorder: 'asc', caption: 'Just simple local grid', height: 'auto' }); 

and JSON data:

 { "total": 1, "page": 1, "records": 2, "rows": [ {"id": "id1", "cell": ["John", " john@example.com "]}, {"id": "id2", "cell": ["Michael", " michael@example.com "]} ] } 

We will get the following results

enter image description here

(see demo )

We are now expanding JSON data with our additional additional information:

 { "total": 1, "page": 1, "records": 2, "rows": [ {"id": "id1", "cell": ["John", " john@example.com "]}, {"id": "id2", "cell": ["Michael", " michael@example.com "]} ], "userdata": { "title": "Das ist der Titel bestimmt beim Server", "columnNames": { "name": "Die Name", "email": "Die E-Mail" } } } 

In the above example, I simply define the userdata header and grid column names in German. To read and use userdata , we can add the following loadComplete event handler to the table:

 loadComplete: function () { var $grid = $(this), columnNames, name, userdata = $grid.jqGrid('getGridParam', 'userData'); if (userdata) { if (userdata.title) { $grid.jqGrid('setCaption', userdata.title); } if (userdata.columnNames) { columnNames = userdata.columnNames; for (name in columnNames) { if (columnNames.hasOwnProperty(name)) { $grid.jqGrid('setLabel', name, columnNames[name]); } } } } } 

Now the same grid will look like

enter image description here

(see another demo )

+12
source

Source: https://habr.com/ru/post/896660/


All Articles