2017-04-20 82 views
0

我已經成功地建立了幾個KendoUI網格,但使用服務器端分頁工作,我不能讓一個。KendoUI網格服務器綁定示例

我修改了我的休息服務,所以我將返回總值(硬編碼現在)。

我也修改了我的JavaScript源。 [見下文]。

通常我只是得到一個空白屏幕。

將是任何幫助,非常感謝。

腳本:

$(document).ready(function(){ 

     // Setup Rest Service 
     var loc = (location.href); 
     var url = loc.substring(0, loc.lastIndexOf("/")) + "/xpRest.xsp/test/"; 


     dataSource = new kendo.data.DataSource({ 
      pageSize: 20, 
      serverPaging: true, 
      serverFiltering: true, 
      serverSorting: true,   transport : { 
       read : { 
        url : url + "READ", 
        dataType : "json" 
       }, 
       type : "READ" 
      }, 
      schema : { 
        total: "total", 
        model : { 
        id : "unid", 
        fields : { 
         unid : { 
          type : "string",  
          nullable : false 
         }, 
          tckNbr : { 
          type : "string", 
          editable : false 
         }, 
          tckSts : { 
          type : "string", 
          editable : false 
         } 
       } 
      } 
     } 
     }); 

      grid = $("#grid-databound-dataItem").kendoGrid({  
      dataSource : dataSource, 
      height: 550, 
      filterable: true, 
      sortable: true, 
      pageable: true,   
      columns : [   
         {field : "tckNbr", title : "Number", type: "string"}, 
         {field : "tckSts", title : "Status", type: "string"} 
         ] 
      }).data("kendoGrid"); 
     }); 

JSON提要:

[ 
    { 
     "total":100, 
     "data": 
     [   
      { 
       "tckNbr":"3031", 
       "tckSts":"1 Not Assigned", 
       "unid":"0014DA9095BF6D638625810700597A36", 
       "tckReqs":"Bryan S Schmiedeler", 
       "tckNts": 
       [ 
       "Bryan DeBaun" 
       ], 
       "tckBUs": 
       [ 
       "NAP\/IFI" 
       ], 
       "tckApps":"GTM", 
       "tckType":"Issue", 
       "tckPriority":"Medium" 
      },   
      { 
       "tckNbr":"3031", 
       "tckSts":"1 Not Assigned", 
       "unid":"00598976D88226D2862581070059AD25", 
       "tckReqs":"Bryan S Schmiedeler", 
       "tckNts": 
       [ 
       "Bryan DeBaun" 
       ], 
       "tckBUs": 
       [ 
       "NAP\/IFI" 
       ], 
       "tckApps":"GTM", 
       "tckType":"Issue", 
       "tckPriority":"Medium" 
      }   
     ] 
    } 
] 

回答

1

糾正你的JSON飼料,你需要返回的對象不是數組:

{ 
    "total": 10, 
    "data": [] 
} 

之後,說什麼是數據和什麼是總在你的模式:

schema : { 
      total: "total", 
      data: "data", 
       . 
       . 
     } 

注意:如果你模擬你的情況下的數據(總數:100,數據 - >大小爲2),你的分頁將由總參數而不是數據本身創建。你會看到5頁有相同的數據(沒關係)。