Is there any way to disable jqgrid local cache???
I have a page which you build some filters and based on this params I create the jqgrid.
The problem is that jqgrid doesn’t change postdata params! I’m mean, on the second, third, fourth, etc search, the results is always equals the first one.
My jqgrid defaults are:
jQuery.extend(jQuery.jgrid.defaults, {
ajaxGridOptions: {
contentType: 'application/json;',
type: "POST",
cache: false,
beforeSend: function () {
$(".loading").show();
}
},
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
datatype: 'json',
autowidth: true,
height: '100%',
rowNum: 10,
rowList: [10, 20, 30],
hidegrid: false,
prmNames: {
search: "isSearch",
nd: null,
rows: "numRows",
page: "numPage",
sort: "orderBy",
order: "orderType"
},
viewrecords: true,
gridComplete: function () {
$(".loading").hide();
},
jsonReader: {
root: function (obj) { return obj.d.rows; },
page: function (obj) { return obj.d.page; },
total: function (obj) { return obj.d.total; },
records: function (obj) { return obj.d.rows.length; },
repeatitems: false
}
});
The jqGrid creation:
$myGrid.jqGrid({
postData: { from: jQuery.parseDate(fromQueryString), to: jQuery.parseDate(toQueryString) },
url: "/Search.aspx/Find",
colNames: ['Test'],
colModel: [
{ name: 'Test', index: 'Test', sortable: false, width: 40 }
],
sortname: "Date",
sortorder: "desc",
jsonReader: { id: "ID" },
pager: "pagerControl",
caption: "Results"
});
If I understand you correctly, the page has come controls build some controls like
input#fromandinput#to(<input>fields with ids “from” and “to”) which defines the interval which you what to send to the server together with other parameters.I suppose that you code looks like
The problem is that the above code is wrong. The
createGridcreate grid only at the first time and then (inside ofmyRefresh) it just dose nothing after the test that the grid$myGridis already created. You can understand this it you imagine that many parts of the grid: the title, the column headers, the pager and so on must be created only once. At the next time one need just reload the content of the grid body.The correct way to refresh jqGrid will be call of
.trigger("reloadGrid")instead of trying to create the grid multiply times. One can fix the code to the followingIn the case the methods
fromandtoof thepostDatawill be called on every grid reload. For example if the user click on the column header to change the grid sorting or if the user choose to display another page of the grid. You can read here more about the approach.The only thing what you can change additionally is the code of
serializeGridDatawhich should test the properties ofpostDataand call the function if needed. See here for details.