Search code examples
jqgridjqgrid-asp.net

Change the Sequence of JqGrid Columns


I wanted to change the grid column sequence dynamically. For e.g. By default the grid will be loaded in LoginId, FirstName and LastName sequence. Based on some condition, I need to change the FirstName and LastName sequence.

Is there any way I can do this?

I tried doing like:

{name:'UserName',index:'UserName',width:82,sortable:false},
if(true)
{
   {name:'FirstName',index:'FirstName',width:65,sortable:false},
   {name:'LastName',index:'LastName',width:65,sortable:false},
}
else
{
   {name:'LastName',index:'LastName',width:65,sortable:false},
   {name:'FirstName',index:'FirstName',width:65,sortable:false},   
}

but I could not get this work.


Solution

  • You can use remapColumns function to do this. In the documentation of the function you will find the example which seems to be wrong, because indexes in the permutation array seem to be 1-based and not 0-based. Try to use:

    $("#list").remapColumns([1,3,2],true,false);
    

    or

    $("#list").remapColumns([1,3,2,4,5,6,7,8,9],true,false);
    

    if you want to change the order of the second and third from the total 9 columns.