I am looking for a way to sort columns programmatically.
Please bare in mind, I do not mean to sort the grid as you normally would with sortGrid() or whatnot. I mean to arrange the row order from left to right programmatically, after the grid has been rendered.
So, I am aware that with:
$("#myGrid").jqGrid({sortable: true});
I am able to sort the columns by dragging and dropping them in order. The idea is to allow users to sort their column, and to have a callback save the order in the database, so each user can arrange their own columns however they want.
I am doing something similar with showing and hiding columns, but have been unable to reorder the columns programmatically without actually dragging and dropping them.
Any help would be highly appreciated.
You can use
remapColumnsmethod to reorder the column programmatically without usage drag & drop.In the answer you will find the code which shows how to save user specific choice of the column order in
localStorage. I personally prefer the way as the saving of the same information on the server side in the database. Nevertheless you can implement saving of the same information in the database instead oflocalStorage. To do this you need just change the implementation ofsaveObjectInLocalStorageandgetObjectFromLocalStoragefunctions and include the ajax call instead of usagewindow.localStorage.