代码之家  ›  专栏  ›  技术社区  ›  bugfixr

jqGrid、datatype:function()和对sord、sidx等的访问

  •  0
  • bugfixr  · 技术社区  · 15 年前

     $("#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();
    }
    

    我唯一不确定的是如何访问用于分页、排序(sord、sidx等)的数据?

    1 回复  |  直到 15 年前
        1
  •  1
  •   Community Mohan Dere    8 年前

    我建议你用标准的 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; }
    }
    

    // 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 d web服务结果的属性(请参阅 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服务的完整代码。您可以使用以下简单的 JSON阅读器 :

    jsonReader: { root: "d.rows", page: "d.page", total: "d.total",
                  records: "d.records", id: "d.names" }
    
    推荐文章