My application users asked if it were possible for pages that contain a jqGrid to remember the filter, sort order and current page of the grid (because when they click a grid item to carry out a task and then go back to it they'd like it to be "as they left it")
Cookies seem to be the way forward, but how to get the page to load these and set them in the grid before it makes its first data request is a little beyond me at this stage.
Does anyone have any experience with this kind of thing with jqGrid? Thanks!
Hi You can make this easier (no other dependency needed) in Pure Js not a jQuery plugin
How to use ?
PS : All modern browsers support native JSON encoding/decoding (Internet Explorer 8+, Firefox 3.1+, Safari 4+, and Chrome 3+). Basically, JSON.parse(str) read more. PSS : the Object i used there is just optimization and removing the dependency of .toJSONstring ... source
Take a look at these jQuery plugins
USE this don't use the custom funcation above https://github.com/carhartl/jquery-cookie
https://github.com/ScottHamper/Cookies
PROBLEM SOLVED
I eventually ended up using cookies in javascript to store the sort column, sort order, page number, grid rows and filter details of the grid (using JSON/Javascript cookies - the
prefs
object)Save Preferences - Called from
$(window).unload(function(){ ... });
Load Preferences - Called from
$(document).ready(function(){ ... });
jqGrid Reference: http://www.secondpersonplural.ca/jqgriddocs/_2eb0fi5wo.htm
BY POPULAR DEMAND - THE FILTERGRID CODE
I part of work what you need you can implement with respect of
jqGridExport
andjqGridImport
(see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:import_methods), but it seems to me you want more as exist out of the box in jqGrid. Some additional features you will have to implement yourself.If the user logs in, you might be able to make AJAX requests back to the server when these parameters change. You could then save the settings, either to database (to make them permanent), to session (to persist them temporarily), or both (for performance reasons).
In any case, with the parameters stored server-side, you could just send them to the page when it is requested.
I was working on the same thing but also needed to get and save the column ordering. It's not simple as jqGrid.remapColumns is relative to what ever the current stat of the grid is...
Just in case anyone finds this helpful (and I'd love to know if there is already something to do this that I missed):