I want to reorder jqGrid columns by column name
or by column index (string)
not by column index (int)
. I have seen this API
$("#list").jqGrid("remapColumns", [0,1,12,3,14,5,6,7,8,11,2], true);
It uses column index number but the problem is after altering the order jqGrid do a reindex and change the index. So i'm looking for the API which accept column name instead of integer value.
This is my code to get the column name
var columnModels = grid.jqGrid('getGridParam', 'colModel');
var user_visibalColumn = [];
for (var columnModelIndex in columnModels) {
var columnModel = columnModels[columnModelIndex];
if (!columnModel.hidden) {
user_visibalColumn.push(columnModel.name);
}
}
//console.log(user_visibalColumn);
So after some time on an event I want to trigger getGridParam
with the above user_visibalColumn
array column.
Is this possible? If not then is there are way to add HTML data-tag col-id so that I can retrieve col-id.
I have seen this answer but I cannot able to figure out how to just implement restoreColumnState
.
Any suggestion will be very helpful.
Thanks.
Please write allays which version of jqGrid you use (or can use) and from, which fork of jqGrid. Moreover it's important to write which fork of jqGrid you use (free jqGrid, commercial Gurrido jqGrid JS or an old jqGrid in version <=4.7).
I agree with the problem of the usage column indexes instead of column names. It's the reason why I made many changes in the free jqGrid fork, which I develop starting with making the main old fork commercial (see the post) in the version 4.7.1. I introduced the method remapColumnsByName
together with the old method remapColumns
. The answer provides the demo, which demonstrates the usage of remapColumnsByName
. Moreover free jqGrid holds mostly column names instead of column indexes internally and it has the helper option iColByName
, which helps to get the current index of the column by the column name.
I recommend you to upgrade jqGrid, which you use to the current (4.13.4) version of free jqGrid and to use remapColumnsByName
.