(I'm sure this is a UFU but I can't seem to find the cause)
Using jqGrid to display data. Double-click on a row opens a new page with drill-down info. I want to restore the filter terms when the 'back' button is clicked.
Filter terms are stored in the localStorage from grid.getGridParam( "postData" ).filters
. Am attempting to restore this at load time but not getting values back.
The confounding factor is probably that I'm creating the values for the filtertoolbar at load time by finding unique values for each column (see here). This says (to me) that I can't set filter values until after the drop-lists are filled. To this end I'm trying to use the 'loadComplete' function (where the list filling function is called). Once the controls are populated I'm calling grid.jqGrid( 'setGridParam', { 'postData' : localStorage[ "filter" ]});
. Unfortunately this doesn't seem to have any effect.
From everything I've read this is doable. What did I miss?
NOTE: I also tried this but figured it wasn't working owing to the values being set in 'loadComplete' above.
EDIT: filter values are being saved here:
ondblClickRow: function( rowid, iRow, iCol, e )
{
localStorage[ 'filter' ] = grid.getGridParam("postData").filters;
window.location = "info.php?idx=" + grid[0].p.data[ rowid - 1 ].IssueId;
}
There are values saved from this. I test when the page is reloaded (and also eyeball it using console.log()
)
loadonce is definitely true.
Here are the params I use:
url: "loadIssues.php",
datatype: "json",
colNames: [ (list of values) ],
colModel: [ (array of values) ],
pager: "#pager2",
viewrecords: true,
sortorder: "desc",
gridview: true,
autoencode: true,
ignoreCase : true,
loadonce : true,
width: 800,
height: "auto",
shrinkToFit: true,
search: true,
jsonReader: {
repeatitems: false,
root: "rows"
},
EDIT:
This is the fix: using the $( this ) was my mistake. Replacing it with a reference to the grid control fixes the problem.
Here is the code I'm using in loadComplete
:
loadComplete: function( data )
{
setSearchSelect( <column name> );
if( localStorage.hasOwnProperty( 'filter' ))
{
postData = $( "#list2" ).jqGrid( "getGridParam", "postData" );
paramNames = $( "#list2" ).jqGrid("getGridParam", "prmNames");
postData.filters = JSON.parse( localStorage[ 'filter' ]);
postData[paramNames.search] = true;
localStorage.removeItem( 'filter' );
setTimeout( function()
{
$( "#list2" ).trigger( "reloadGrid" );
}, 100 );
}
}