jqGrid postData和过滤

时间:2011-08-11 22:16:00

标签: javascript jqgrid

我整天都在苦苦挣扎。我的要求非常简单:我正在使用单场搜索。我想在离开页面时保存网格的状态(使用postData和cookie),并在我回来时恢复它。我可以将postData保存到cookie中,但无法弄清楚如何再次恢复网格状态。

$(document).ready(documentReady);
function documentReady()
{
  $("#grid_clients").jqGrid({
      datatype: "local",
      height: 200,
      width: 832,
      shrinkToFit: true,
      caption:"Clients",
      colNames :["","Id","Name","Description","Active<br />Studies"],
      colModel :[
        {name:"edit", index:"edit", width:20, align:"center", sortable:false, search: false},
    {name:"id", index:"id", width:40, align:"right", sorttype:'int'},
    {name:"name", index:"name", width:200},
    {name:"description",    index:"description",    width:200},
    {name:"studycount", index:"studycount", width:50,   align:"right", sorttype:'int'}
          ],
      pager:"pager_clients",
      scroll: 1,
      viewrecords:true,
      sortable:true,
      sortname: "name",
      autowidth: true,
      pgbuttons: false,
      loadonce: true,
      gridview: true
   });

   $("#grid_clients").jqGrid("navGrid", "#pager_clients",{add:false, edit:false, del:false});

   $('#grid_clients').jqGrid('setGridParam', {datatype: 'xml'}); 
   var gridUrl = 'getgridxmlclients.php';
   $('#grid_clients').jqGrid('setGridParam', {url: gridUrl});

   // If the cookie exists, set the postData and search parameters. 
   if ($.cookies.get('gridPostData')) 
   {
      alert(dump($.cookies.get('gridPostData')));
      $('#grid_clients').jqGrid('setGridParam', {search: true, 'postData': $.cookies.get('gridPostData')});
   }

   $('#grid_clients').trigger('reloadGrid', [{page:1}]);
}

返回页面时cookie的警报如下所示:

 '_search' => "true"
 'nd' => "1313100751399"
 'rows' => "20"
 'page' => "1"
 'sidx' => "id"
 'sord' => "asc"
 'searchField' => "studycount"
 'searchString' => "1"
 'searchOper' => "eq"
 'filters' => ""

有趣的是,参数似乎已经采用了,因为如果我只是点击标题来对网格进行排序,那么过滤器会起作用。我在重新加载时错过了强制过滤的方法。

谢谢, - 大卫

0 个答案:

没有答案