Alex Rivera | Logout

How can I get JQGrid to recognize server sent Errors?

Asked 2009-10-28T11:07:46.403
22

I have a jqgrid that's functionning very well.

I was wondering is it possible to catch server sent errors ? how Is it done ?

Edit
Report

2 Answers

7

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:

  • ColumnNames: string[]
  • ColumnModels: object[] (each object has the properties "name", "index" and "sortable")
  • Data: object[] (each object has properties that match the names in the column model)
  • TotalRows: int

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
answered 2009-11-10T19:34:49.283
1

Another thing to remember/ or that I found is that if you are using Asp.net you need to turn

in the section - this will allow you to introspect the Message coming back as well.

answered 2013-06-04T02:04:12.620

Your Answer