2011-11-04 86 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