views:

70

answers:

1

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.

A: 

You can use remapColumns function to do this. In the documentation of the function you will find the example which seems be wrong, because indexes in the permutation array seams 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.

Oleg
Thanks for the reply. I am using jqGrid 3.5.3 version library. Is this feature available in this version?
Amar
@Amar: I have no idea. Is it now work? You should post a code example which can reproduce your problem. I am only a user and not a developer of jqGrid. On the page http://www.trirand.com/jqgridwiki/doku.php?id=wiki:change#jqgrid_3.7.2_changes_and_fixes there are no information about changes in `remapColumns`, but I am not sure. It seems to me there are some bug fixes in the time. Why you don't download from http://www.trirand.com/blog/?page_id=6 and use the last version of jqGrid?
Oleg
Thanks Oleg for the quick reply. I checked for the remapColumns method and it is not present in the 3.5.3 version. I am upgrading my jqgrid to latest version now. Thanks once again.
Amar
@Amar: You welcome! I recommend you to test the program after the usage of `remapColumns` more carefull. I had seen a lot of bugs in the `columnChooser` (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:jquery_ui_methods#column_chooser) which use `remapColumns`. If you will find a new bug post it to the http://www.trirand.com/blog/?page_id=393/bugs/.
Oleg