2011-11-04 90 views
0

我一直在努力让这个工作了很多天了。jqGrid加载aspx webservice使用mtype发布json不加载网格

奇怪的是,我得到它通过各种试验来排序的工作 - 但现在它不是在所有

这里加载是我的设置:

$("#table-Select").jqGrid({ 
         url: 'SelectionListService.asmx/GetList', 
         mtype: 'POST', 
         datatype: 'json', 
         ajaxGridOptions: { contentType: 'application/json; charset=utf-8' }, 
         postData: { SelectionType: 'Project' }, 
         colNames: ['id', 'Title', 'DocumentID'], 
         colModel: [ 
            { name: 'id', index: 'id', width: 20,hidden: false }, 
            { name: 'Title', index: 'Title' ,width: 220,hidden:false}, 
            { name: 'DocumentID', index: 'DocumentID',width: 220, hidden: false} 
            ], 
         hidegird: false, 
         autowidth: true, 
         //height: 'auto', 
         rowNum: 0, 
         rowList: [10, 20, 30], 
         pager: jQuery('#table-SelectPager'), 
         sortname: 'Title', 
         viewrecords: true, 
         loadonce: true, 
         sortorder: "desc", 
         caption: "Select Project", 
         //fixes Invalid JSON Primitive error 
         serializeGridData: function (postData) { 
           if (postData.searchField === undefined) postData.searchField = null; 
           if (postData.searchString === undefined) postData.searchString = null; 
           if (postData.searchOper === undefined) postData.searchOper = null; 
           //if (postData.filters === undefined) postData.filters = null; 
           return JSON.stringify(postData); 
          }, 
         jsonReader: { 
          root: "rows", 
          page: "page", 
          total: "total", 
          records: "records" 
          } 

         }).navGrid('#table-SelectPager', { edit: false, add: false, del: false }); 

这里是JSON数据从WebService来拨打:

{"d":{"__type":"NCR.SelectionListService+JQGrid","page":1,"total":4,"records":4,"rows":[{"id":"1","DocumentID":"pgmprj://aecomme/newdohaportproject/envcomp","Title":"NDPP-Environmental Compliance Monitoring"},{"id":"2","DocumentID":"pgmprj://aecomme/newdohaportproject/ndpp-portbasinandinnerbreakwatersconstruction","Title":"NDPP-Port Basin and Inner Breakwaters Construction"},{"id":"3","DocumentID":"pgmprj://aecomme/newdohaportproject/ndpp-programmanagement","Title":"NDPP-Program Management"},{"id":"4","DocumentID":"pgmprj://aecomme/newdohaportproject/ndpp-supplementarysiteinvestigation","Title":"NDPP-Supplementary Site Investigation"}]}} 

我知道这一定是一些简单的我失踪 - 但是毕竟我已经看过的例子 - 我不知道我错过了什么。

任何想法将不胜感激。

回答

0

你应该修改jsonReader选项如下:

jsonReader: { 
    root: "d.rows", 
    page: "d.page", 
    total: "d.total", 
    records: "d.records", 
    repeatitems: false 
} 

the demo

+0

非常感谢Oleg--我刚刚击中那一个,你也击败了我 - 再次感谢。奇怪的是,当我点击Sort函数时 - 所有的行都消失了 - 即使所有的记录都依然存在(根据$(“#table-Select”)。jqGrid('getGridParam',“records”); – Nutshell

+0

***更新***,发现排序问题,出于某种原因,我在某人的例子rowNum:0,因此我试图设置这个在我的设置,它加载第一次发现,但后来这样做导致排序清除网格上的记录。爱jqGrid - 谢谢奥列格! – Nutshell

+0

@Nutshell:我刚刚发现了同样的问题。你还应该在'id'列中加入'sorttype:'int''。看修改的演示。如果问题解决了,你可以[“接受”](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235)答案。 – Oleg