2017-04-20 81 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页有相同的数据(没关系)。