如何获得JQGrid识别服务器发送的错误? [英] How can I get JQGrid to recognize server sent Errors?

查看:56
本文介绍了如何获得JQGrid识别服务器发送的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行良好的jqgrid.

I have a jqgrid that's functionning very well.

我想知道是否有可能捕获服务器发送的错误?如何完成?

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

推荐答案

我最近在为CB Richard Ellis(我的雇主)从事的原型项目中广泛使用了jqgrid.如文档所述,有很多填充jqgrid的方法:(请参见检索数据"节点.

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

当前,我进行服务调用,该服务返回一个json字符串,该字符串在求值时会给我一个包含以下内容的对象:

Currently I make a service call that returns a json string that when evaluated, gives me an object that contains the following:

  • ColumnNames:字符串[]
  • ColumnModels:object [](每个对象都具有名称",索引"和可排序"属性)
  • 数据:对象[](每个对象具有与列模型中的名称匹配的属性)
  • TotalRows:整数

在成功回调中,我像这样手动创建jqgrid :(数据"是我在评估返回的json字符串时得到的对象).

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]);

因此您可以看到我手动填充了数据.超过一种服务器错误.存在逻辑错误,您可以将其作为json字符串中的属性返回,并在尝试创建jqgrid之前(或逐行)进行检查.

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

或每行

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

如果您的错误是服务器上未处理的异常,那么您可能需要在异步调用中进行错误回调.在这种情况下,根本不会调用(大概)正在创建jqgrid的成功回调.

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.

这当然适用于手动填充jqgrid,这只是可用的许多选项之一.如果您将jqgrid直接连接到服务调用或用于检索数据的函数,则完全是另一回事.

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.

在文档页面上,在基本网格">事件"下查看.在那里,您会看到可能有用的"loadError"事件.

On the documentation page, look under Basic Grids > Events. There you'll see the "loadError" event that might come in handy.

这篇关于如何获得JQGrid识别服务器发送的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆