In my project, I have a scenario in which a user can drag and drop jqGrid columns. When the same user visits the site again, we have to display the jqGrid column order how he had modified in his previous visit. So, the order of jqGrid columns should be user specific. Can anyone help me how to achieve this? (and I need return type and format of jQgrid column).
Asked
Active
Viewed 842 times
0
-
To store some user specific information you can use **cookies**, **sessionStorage** or **localStorage** – Krzysztof Safjanowski Aug 02 '14 at 10:03
-
if possible can you explain with sample code. am new to jQgrid – venkat Aug 02 '14 at 10:11
-
can you please tell me what is return type of jQGrid column and return format of jQgrid column? – venkat Aug 02 '14 at 10:33
1 Answers
2
The implementation of behavior which you need is not very simple. I would recommend you to save the changed column order in localStorage
like it described in the answer and this one. Try the old demo using Column Chooser button first.
To save changed column order you need to register the callback which jqGrid should call after drag&drop of column headers. One can use update
callback of sortable
option defined as object (instead of true
). So the code will be like
var $grid = $("#list"); // your grid
...
$grid.jqGrid({
... // all other option of jqGrid
sortable: {
update: function (perm) {
saveColumnState.call($grid, perm); // save permutation
}
}
});
The function saveColumnState
are described in the referenced above answers and are included in the referenced above demo too.
-
Hi Oleg, thanks for your comment. I want to save the column order in database(sql server). Can you please tell me how to do this? to do this i need return type (format) of jqgrid column. can you please help me on this.? – venkat Aug 03 '14 at 02:03
-
You need to change the implementation of `saveColumnState` method of [the demo](). The last line of the current implementation calls `saveObjectInLocalStorage(myColumnStateName(this), columnsState);` where `columnsState` is the object which need be saved. You can make Ajax request to the server instead. In the same way `restoreColumnState` need to get the state from the server using Ajax call instead of `getObjectFromLocalStorage`. – Oleg Aug 03 '14 at 04:33
-
Thanks Oleg for your inputs. Am new to jquery , jqgrid and ajax. can you please explain in detail what are the steps i supposed to do this task( saving column order in jqgrid)? – venkat Aug 03 '14 at 05:22
-
what is the format of "columState" object which we are going to save in database? please help me on this. advanced thanks – venkat Aug 03 '14 at 05:29
-
@venkat: You are welcome! You should make [jQuery.ajax](http://api.jquery.com/jquery.ajax/) call with `data: columnsState` and `url` with your server handler. What you do on the server side is very different depend on what you use in your server side code. I'm now on the way to vacation, so can't get you more information. – Oleg Aug 03 '14 at 05:41
-
if possible please provide me the format in which jqgrid column returns? remaining things i will take care? – venkat Aug 03 '14 at 06:03
-
What exactly jqgrid columns are going to return. i want to save that order in database.(format). – venkat Aug 04 '14 at 09:44