Asp.net jqGrid,数据类型:function()和对sord、sidx等的访问
我试图在承载网格的页面上使用WebMethod实现jqGrid。如果我在jqGrid中使用dataType:function(),则此操作有效:Asp.net jqGrid,数据类型:function()和对sord、sidx等的访问,asp.net,jquery,jqgrid,Asp.net,Jquery,Jqgrid,我试图在承载网格的页面上使用WebMethod实现jqGrid。如果我在jqGrid中使用dataType:function(),则此操作有效: $("#mygrid").jqGrid({ ... datatype: function() { $.ajax({ url: "myPage.aspx/gridData", type: "POST", contentType:
$("#mygrid").jqGrid({
...
datatype: function() {
$.ajax({
url: "myPage.aspx/gridData",
type: "POST",
contentType: "application/json; char=utf-8"
...
});
}
)};
在同一页的代码隐藏中,我有我的方法:
[WebMethod()]
public static List<MyData> gridData() {
return MyClass.getData();
}
[WebMethod()]
公共静态列表gridData(){
返回MyClass.getData();
}
我唯一不确定的是如何访问用于分页、排序(sord、sidx等)的数据
提前感谢。我建议您使用标准的
数据类型:“json”
而不是数据类型作为函数。你只需要额外使用
datatype: 'json',
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
mtype: 'GET',
(参见示例)
并返回定义如下的jqGridTable类实例
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; }
}
// 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
}
添加到服务的参数列表
更新:另一个链接几乎包含jqGrid和ASMX服务的完整代码。您可以使用以下简单的jsonReader
:
jsonReader: { root: "d.rows", page: "d.page", total: "d.total",
records: "d.records", id: "d.names" }
事实上,我之前遇到过你的例子。第一部分缺少“ts”的定义,因此它不起作用,我不确定它是什么。有什么建议吗?此外,如果我没有弄错的话,出于安全考虑,我不能将“get”与json一起使用。如果出现post,Web服务只会用json回复。您可能是指ts
from。它只是jqGrid源代码中的一个代码片段。您可以从下载完整的源代码。您确实可以将HTTP GET与JSON一起使用。关于安全性,你可能指的是JSON注入。这是一个单独讨论的主题。在我的主要项目中,我使用jqGrid,例如,我使用HTTPGET和have安全解决方案。我们应该详细解释一下。谢谢你的提示。我正在找到一个有效的解决方案。欢迎您!如果你有其他问题,你可以问我更多。至少你应该有一个可行的解决方案。如果您有问题,我可以使用jqGrid和asmxweb服务发布一个带有可工作的visualstudio项目的url。
jsonReader: { root: "d.rows", page: "d.page", total: "d.total",
records: "d.records", id: "d.names" }