Report user errors in jQGrid
I have a jqgrid table querying a MySQL DBMS through an apache2 web server via XML.
Sometimes whenever the DB s开发者_StackOverflow中文版erver shuts down or the server side program encounters some kind of crashes the jqgrid just freezes down waiting for the XML data to arrive.
In this kind of situation, I would be preferable to make the jqgrid user aware of this matter and thus display a gentle message describing the type of the annomaly.
I was wondering is there any jqgrid option specific for this kind of situation
I'm using:
jquery-1.3.2
jquery-ui-1.7.2
jquery.jqGrid-3.5.3
Thanks,
If for the jqgrid you are using the function
datatype with jQuery.agax
then place your logic in the error handler. The only problem with this is that you manually have to populate the grid and you don't get the "Loading" hint, though you can create one.
This sample was taken from the usual pattern that I use when calling ASP.NET WCF services, my results object contains int properties for the pager and a rows collection, this is defined in myGrid.setGridParams
.
datatype: function(postdata) {
$.ajax({
type: "POST",
url: 'SomeService.svc/SomeGetMethod',
data: JSON.stringify(postdata),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(res) {
myGrid.clearGridData();
for (var i = 0; i < res.d.rows.length; i++) {
myGrid.addRowData(i + 1, res.d.rows[i]);
}
myGrid.setGridParam({
page: postdata.page,
lastpage: res.d.total,
records: res.d.records,
total: res.d.total
});
myGrid.each(function() {
if (this.grid) this.updatepager();
});
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// Code to handle error.
}
});
},
I answered a similar question regarding the reporting of (server side) errors with a jqgrid.
How can I get JQGrid to recognize server sent Errors?
You can use the loadError
event in jqGrid definition (see documentation). E.g.:
//Catch errors
loadError = function(xhr, textStatus, errorThrown) {
var error_msg = xhr.responseText
var msg = "Some errors occurred during processing:"
msg += '\n\n' + error_msg
alert(msg)
}
精彩评论