簡體   English   中英

我如何解決jqGrid排序,分頁的問題?

[英]How i can solve problems with jqGrid sorting, paging?

好的,我將服務器端代碼更改為

  int nm = objects.ToList().Count;
  if (objects.ToList().Count > 0)
       return new PagedList(objects, nm, 1, 25, null);
  else return null;

json更改為

{“ d”:{“ total”:15,“ page”:1,“ records”:366,“ rows”:[{“ id”:“ 34324”,“ LastDateChange”:“ / Date(1391464800000)/” ,“ DateLoad”:“ / Date(1391464800000)/” ....,“ AName”:“ fg”}],“ userData”:null}}

客戶端

   $("#table").jqGrid({
    url: '/WebSrv.asmx/GetSaleObjects',
    datatype: 'json',
    mtype: 'POST',
    loadonce: true,
   ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
   serializeGridData: function (postData) {
   },
   viewrecords: true,
   sortable: true,
   gridview: true,
   multisort: true,
   height: 'auto',
   width: 'auto',
   pager: "#pgrf",
   autowidth: true,
   pagination: true,
    jsonReader: {
       root: "d.rows",
       page: "d.page",
       total: "d.total",
       records: "d.records"
   }
 ....
   }); 

但是網格是空的! 不要理解;(,可能是樣品嗎?

看來您得到了非常古老的示例作為解決方案的模板。 例如,在版本3.5中已棄用了imgpath選項(請參閱文檔 )。 因此,您使用了為版本5以前的jqGrid版本創建的模板。

您代碼中的另一個重要錯誤是ASMX Web服務方法內部使用了手動JSON序列化。 您應該從GetSaleObjects刪除對Newtonsoft.Json.JsonConvert.SerializeObjectGetSaleObjects 該方法應返回PagedList對象或僅返回Object 順便說一下new PagedList(objects, objects.ToList().Count, 1, objects.ToList().Count)在使用loadonce: true情況下,您可以返回objects (或objects.ToList() )而不是new PagedList(objects, objects.ToList().Count, 1, objects.ToList().Count) loadonce: true因為jqGrid 忽略pagerecordstotal在的情況下,服務器響應的部分loadonce: true

重要的是要了解當前代碼兩次將結果序列化為JSON。 因此,您必須在$.ajax success句柄內部調用JSON.parse 例如,如果您有一個new PagedList(...)對象,則將firs序列化為JSON會產生如下字符串

{"total":1,"page":1,"records":350,"rows":[...]}

ASP.NET 對返回的結果進行序列化。 所以一個修改返回值到字符串

"{\"total\":1,\"page\":1,\"records\":350,\"rows\":[...]}"

對正確的JSON字符串( {"total":1,"page":1,"records":350,"rows":[...]}反序列化將在客戶端上產生具有屬性totalrows等的對象一面。 在錯誤的字符串的另一側的反序列化( {\\"total\\":1,\\"page\\":1,\\"records\\":350,\\"rows\\":[...]} 產生包含文本{"total":1,"page":1,"records":350,"rows":[...]} 字符串 僅當一個應用附加調用jQuery.parseJSONJSON.parse一個才會獲得必需的對象

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM