I'm aware of this answer: How do I add a cancel button to my jqgrid?, and I'm attempting to implement something similar, although without a button to trigger the cancel. Iv'e got a grid that loads on page load (a search that by default loads with no criteria) and I'd like to be able to cancel that default empty criteria search when the user actually executes a search with criteria. Since I don't need a button I'm trying to simplify the solution by merely keeping track of the xhr request in the loadBeforeSend method, and abort that xhr if it is not null as I load the grid. Code:
var gridXhr;
function getGridData() {
var searchParms = ...;
var colHeaders = [...];
var colDefinitions = [...];
if (gridXhr != null) {
alert(gridXhr.readyState);
gridXhr.abort();
gridXhr = null;
}
$('#grid').jqGrid('GridUnload');
$('#grid').jqGrid({
defaults: {...},
autowidth:true,
url: "<%= Page.Request.Path %>/ExecuteSearch",
mtype: 'POST',
ajaxGridOptions: { contentType: "application/json" },
postData: searchParms,
datatype: "json",
prmNames: {
nd: null,
rows: null,
page: null,
sort: null,
order: null
},
jsonReader: {
root: function (obj) { return obj.d; },
page: function (obj) { return 1; },
total: function (obj) { return (obj.d.length / 20); },
records: function (obj) { return obj.d.length; },
id: 'CatalogID',
cell: '',
repeatitems: false
},
loadonce: true,
colNames: colHeaders,
colModel: colDefinitions,
caption: "Search Results",
pager: 'searchPaging',
viewrecords: true,
loadBeforeSend: function (xhr) {
gridXhr = xhr;
},
loadError: function (xhr, status, error) {
gridXhr = null;
if (error != 'abort') {
alert("Load Error:" + status + "\n" + error);
}
},
loadComplete: function() {
gridXhr = null;
},
multiselect: <%= this.MultiSelect.ToString().ToLower() %>,
multiboxonly: true
}).setGridWidth(popWidth);
}
The problem I'm having is that subsequent executions of the jqGrid don't work. The loadError function is triggered, with an error (3rd parameter) of "abort." Do I need to do something more/different with the loadBeforeSend as done in the other answer?
Also, Oleg mentioned in his sample code myGrid[0].endReq();
and I can find no mention of that in the documentation - does that function exist?