I have a jqgrid that's functionning very well.
I was wondering is it possible to catch server sent errors ? how Is it done ?
If you look at the jqgrid demo site and look at "What's new in version 3.2" There should be a section about controlling server errors.
Specifically, it uses a callback parameter loadError:
loadError : function(xhr,st,err) { jQuery("#rsperror").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText); }
As mcv states above, some errors are data errors, so you'll need to handle those specifically.
I have recently made extensive use of jqgrid for a prototype project I am working on for CB Richard Ellis (my employer). There are many way to populate a jqgrid, as noted in the documentation: (see the "retrieving data" node).
Currently I make a service call that returns a json string that when evaluated, gives me an object that contains the following:
In my success callback, I manually create the jqgrid like this: ("data" is the object I get when evaluating the returned json string).
var colNames = data.ColumnNames; var colModel = data.ColumnModels; var previewData = data.PreviewData; var totalRows = data.TotalRows; var sTargetDiv = userContext[0]; // the target div where I'll create my jqgrid $("#" + sTargetDiv).html("<table cellpadding='0' cellspacing='0'></table>"); var table = $("#" + sTargetDiv + " > table"); table.jqGrid({ datatype: 'local', colNames: colNames, colModel: colModel, caption: 'Data Preview', height: '100%', width: 850, shrinkToFit: false }); for (var row = 0; row < previewData.length; ++row) table.addRowData(row, previewData[row]);
So you can see I manually populate the data. There is more than 1 kind of server error. There is the logical error, which you could return as a property in your json string, and check before you try to create a jqgrid (or on a per-row basis).
if (data.HasError) ...
Or on a per-row basis
for (var row = 0; row < previewData.length; ++row) { if (previewData[row].HasError) // Handle error, display error in row, etc ... else table.addRowData(row, previewData[row]); }
If your error is an unhandled exception on the server, then you'll probably want an error callback on your async call. In this case, your success callback that (presumably) is creating your jqgrid won't be called at all.
This, of course, applies to manually populating a jqgrid, which is only one of the many options available. If you have the jqgrid wired directly to a service call or a function to retrieve the data, then that's something else entirely.
On the documentation page, look under Basic Grids > Events. There you'll see the "loadError" event that might come in handy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With