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(){ ... });
var filters = {
fromDate: $('#fromDateFilter').val(),
toDate: $('#toDateFilter').val(),
customer: $('#customerFilter').val()
};
prefs.data = {
filter: filters,
scol: $('#list').jqGrid('getGridParam', 'sortname'),
sord: $('#list').jqGrid('getGridParam', 'sortorder'),
page: $('#list').jqGrid('getGridParam', 'page'),
rows: $('#list').jqGrid('getGridParam', 'rowNum')
};
prefs.save();
Load Preferences
- Called from $(document).ready(function(){ ... });
var gridprefs = prefs.load();
$('#fromDateFilter').val(gridprefs.filter.fromDate);
$('#toDateFilter').val(gridprefs.filter.toDate);
$('#customerFilter').val(gridprefs.filter.customer);
$('#list').jqGrid('setGridParam', {
sortname: gridprefs.scol,
sortorder: gridprefs.sord,
page: gridprefs.page,
rowNum: gridprefs.rows
});
// filterGrid method loads the jqGrid postdata with search criteria and re-requests its data
filterGrid();
jqGrid Reference: http://www.secondpersonplural.ca/jqgriddocs/_2eb0fi5wo.htm
BY POPULAR DEMAND - THE FILTERGRID CODE
function filterGrid() {
var fields = "";
var dateFrom = $('#dateFrom').val();
var dateTo = $('#dateTo').val();
if (dateFrom != "") fields += (fields.length == 0 ? "" : ",") + createField("shipmentDate", "ge", dateFrom);
if (dateTo != "") fields += (fields.length == 0 ? "" : ",") + createField("shipmentDate", "le", dateTo);
var filters = '"{"groupOp":"AND","rules":[' + fields + ']}"';
if (fields.length == 0) {
$("#list").jqGrid('setGridParam', { search: false, postData: { "filters": ""} }).trigger("reloadGrid");
} else {
$("#list").jqGrid('setGridParam', { search: true, postData: { "filters": filters} }).trigger("reloadGrid");
}
}
function createField(name, op, data) {
var field = '{"field":"' + name + '","op":"' + op + '","data":"' + data + '"}';
return field;
}