title: jqGrid: restoring filter (toolbar) values on page reload
body: <p>(I'm sure this is a UFU but I can't seem to find the cause)</p>
  
  <p>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. </p>
  
  <p>Filter terms are stored in the localStorage from <code>grid.getGridParam( "postData" ).filters</code>. Am attempting to restore this at load time but not getting values back.</p>
  
  <p>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 <a href="https://stackoverflow.com/questions/5328072/can-jqgrid-support-dropdowns-in-the-toolbar-filter-fields">here</a>). 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 <code>grid.jqGrid( 'setGridParam', { 'postData' : localStorage[ "filter" ]});</code>. Unfortunately this doesn't seem to have any effect.</p>
  
  <p>From everything I've read this is doable. What did I miss?</p>
  
  <p>NOTE: I also tried <a href="https://stackoverflow.com/questions/4973361/how-can-i-preserve-the-search-filters-in-jqgrid-on-page-reload">this</a> but figured it wasn't working owing to the values being set in 'loadComplete' above.</p>
  
  <hr>
  
  <p>EDIT: filter values are being saved here:</p>
  
  <pre><code>ondblClickRow: function( rowid, iRow, iCol, e )
  {
      localStorage[ 'filter' ] = grid.getGridParam("postData").filters;
      window.location = "info.php?idx=" +  grid[0].p.data[ rowid - 1 ].IssueId;
  }
  </code></pre>
  
  <p>There <strong>are</strong> values saved from this. I test when the page is reloaded (and also eyeball it using <code>console.log()</code>)</p>
  
  <p><strong>loadonce</strong> is definitely <strong>true</strong>.</p>
  
  <p>Here are the params I use:</p>
  
  <pre><code>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"
   },
  </code></pre>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>This is the fix: using the $( this ) was my mistake. Replacing it with a reference to the grid control fixes the problem.</p>
  
  <p>Here is the code I'm using in <code>loadComplete</code>:</p>
  
  <pre><code>loadComplete: function( data )
  {
      setSearchSelect( &lt;column name&gt; );
  
      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 );
     }
  }
  </code></pre>