我建议您使用标准datatype: 'json'
而不是datatype
作为功能。你只需要使用额外
datatype: 'json',
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
mtype: 'GET',
(见Setting the content-type of requests performed by jQuery jqGrid例如)
,并返回类似以下
public class jqGridTable
{
public int total { get; set; } // total number of pages
public int page { get; set; } // current zero based page number
public int records { get; set; } // total number of records
public List<jqGridRow> rows { get; set; }
}
public class jqGridRow
{
public string id { get; set; }
public List<string> cell { get; set; }
}
定义jqGridTable类的实例或者,如果我们要使用从传输的数据中最紧凑的形式服务器到客户端然后以下
// jsonReader: { repeatitems : true, cell:"", id: "0" }
public class jqGridTable {
public int total { get; set; } // total number of pages
public int page { get; set; } // current zero based page number
public int records { get; set; } // total number of records
public List<List<string>> rows { get; set; }// first element of row must be id
}
可能您应该使用其他一些jsonReader
来解码来自Web服务结果的d
属性的数据(请参阅Jqgrid 3.7 does not show rows in internet explorer)。
为了支持服务器端分页和排序您应该添加
int page, int rows, string sidx, string sord
到的服务参数列表。
已更新:其他链接jqgrid Page 1 of x pager实际上具有jqGrid和ASMX服务的完整代码。你可以使用以下简单的jsonReader
:
jsonReader: { root: "d.rows", page: "d.page", total: "d.total",
records: "d.records", id: "d.names" }
我实际上遇到过你的例子。第一部分缺少“ts”定义,所以它不起作用,我不确定它是什么。有小费吗? 另外,如果我没有弄错,因为安全性,我不能使用json的“get”。如果发布帖子,web服务只会在json中回应。 – bugfixr 2010-08-05 01:09:32
也许你的意思是'ts' from http://stackoverflow.com/questions/2675625/setting-the-content-type-of-requests-performed-by-jquery-jqgrid/2678731#2678731。它只是来自jqGrid源代码的代码片段。您可以从http://www.trirand.com/blog/?page_id=6下载完整的源代码。您可以使用JSON使用HTTP GET。关于安全性你可能意味着JSON注入。这是一个单独讨论的话题。在我使用jqGrid的主项目中,我使用HTTP GET并且有安全的解决方案。人们应该详细解释这一点。 – Oleg 2010-08-05 01:34:59
感谢Oleg的提示。我很快就有了一个工作解决方案。 – bugfixr 2010-08-05 14:57:50