jqGrid postData and filtering
I have been struggling with this all day. My requirement is very simple: I'm using single field searching. I want to save the state of the grid (using postData and a cookie) when I leave the page and restore it when I come back. I'm able to save the postData to a cookie, but can't figure out how to restore the grid state again.
$(document).ready(documentReady);
function documentReady()
{
$("#grid_clients").jqGrid({
datatype: "local",
height: 200,
width: 832,
shrinkToFit: true,
caption:"Clients",
colNames :["","Id","Name","Description","Active开发者_JAVA技巧<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}]);
}
The alert for the cookie when coming back to the page looks like this:
'_search' => "true"
'nd' => "1313100751399"
'rows' => "20"
'page' => "1"
'sidx' => "id"
'sord' => "asc"
'searchField' => "studycount"
'searchString' => "1"
'searchOper' => "eq"
'filters' => ""
The interesting thing is that the parameters seem to have taken, because if I just click on a header to sort the grid, the filter takes affect then. I'm missing the method of forcing the filtering when reloading.
Thanks, --David
精彩评论