2017-03-31 31 views
0

因此,我試圖用顯示數據的kendo製作一個現成的網格,但無論我做什麼,數據都不會顯示。儘管在DataSource中有數據,Kendo Grid並不顯示任何數據

The grid looks like this

而這裏的代碼:

$("#Materials") 
     .kendoGrid({ 
      dataSource: { 
       data: [], 
       schema: { 
        model: { 
         id: "ID", 
         fields: { 
          ID: { type: "number", editable: false }, 
          Code: { type: "string", editable: false }, 
          Name: { type: "string", editable: false }, 
          ExtDeviceCode: { type: "string", editable: false , nullable: true }, 
          BaseUomLOVString: { type: "string", editable: false } 
         } 
        } 
       }, 
       pageSize: 20 
      }, 
      filterable: { 
       extra: true 
      }, 
      pageable: true, 
      columns: [ 
       { field: "Code", title:"Code"}, 
       { field: "Name", title: "Name"}, 
       { field: "ExtDeviceCode", title:"External device code"}, 
       { field: "BaseUomLOVString", title: "UnitsOfMeasure" } 
      ], 
      editable: false 
     }); 

這使得沒有數據,這是我後來與一個Ajax調用填充空網格。從上圖可以看出,網格包含數據,但不顯示它。該數據源looks like this.的Json內或數據:

[{ 
    "ID": 21150, 
    "Code": "3", 
    "ExtDeviceCode": null, 
    "Name": "Avio benzin", 
    "BaseUomLOVString": "Kilogram" 
}, { 
    "ID": 21400, 
    "Code": "5003", 
    "ExtDeviceCode": null, 
    "Name": "Bencin 95", 
    "BaseUomLOVString": "Litre" 
}] 

編輯1

  $.ajax({ 
       url: '@SimpleUrlHelper.UrlObjectToRoot(Url)/FuelPointMaterialTankMask/LookupMaterials', 
       data: { 
        //Send list of IDs 
        'materialIDs': materialList 
       }, 
       type: "POST", 
       success: function (response) { 

        var tmp = []; 
        if (typeof response !== "undefined" && 
        response !== null) { 
         response.forEach(function(item) { 
          tmp.push(item); 
         }); 
        } 
        grid = $("#Materials").data("kendoGrid"); 
        originalMaterialDataSource = grid.dataSource; 
        originalMaterialDataSource.data(tmp); 
        originalMaterialDataSource._destroyed = []; 
        originalMaterialDataSource.pageSize(pageSize); 
        originalMaterialDataSource.page(1); 
        originalMaterialDataSource._total = tmp.length; 
        grid.pager.refresh(); 
       } 
      }); 
+0

在ajax調用之後如何填滿網格? – ezanker

+0

對不起,遲到的迴應!將上面的Ajax調用代碼添加到「編輯」段落中。 – DisplayName

回答

0

好了,所以試圖弄清楚什麼是錯的,我終於找到了答案天后。

沿線某處我:

var grids = $('.k-grid'); 
for (var i = 0; i < grids.length; i++) { 
     .... 
grid.dataSource.filter().filters[0] = { 
     logic: "or", 
     filters: filters 
} 
     .... 

所以基本上我是把所有的網格過濾器,但不排除這一項,這是剛剛從我的一個錯誤。

0

您可以在數據源設置你的數據:我有一個Ajax調用這樣的填充數據在你的ajax調用之後。

var dataArray = [{ 
    "ID": 21150, 
    "Code": "3", 
    "ExtDeviceCode": null, 
    "Name": "Avio benzin", 
    "BaseUomLOVString": "Kilogram" 
}, { 
    "ID": 21400, 
    "Code": "5003", 
    "ExtDeviceCode": null, 
    "Name": "Bencin 95", 
    "BaseUomLOVString": "Litre" 
}]; 

使用.data()設置:

$("#Materials").data('kendoGrid').dataSource.data(dataArray); 
+0

一旦網格創建並且結果相同,我確實嘗試用代碼填充數據。 dataSource.data()的數據在$('#Materials')。data('kendoGrid')。dataSource.view()總是空的,不顯示任何內容。就好像網格被摺疊一樣。 – DisplayName