Yngwie
Yngwie

Reputation: 47

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 server 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,

Upvotes: 2

Views: 4213

Answers (3)

Don
Don

Reputation: 17606

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)
    }

Upvotes: 0

Samuel Meacham
Samuel Meacham

Reputation: 10415

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?

Upvotes: 1

Brett Ryan
Brett Ryan

Reputation: 28255

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.
      }
   });
},

Upvotes: 1

Related Questions