2016-11-15 122 views
1

我有劍道網格列如下:復位劍道網格列

$("#lstCategory").kendoGrid({ 
     dataSource: { 
      data: info, 
      autoSync: true, 
      schema: { 
       model: { 
        fields: { 
         category: { editable: false, type: "string" }, 
         subCategory: { editable: false, type: "string" } 
        } 
       } 
      }, 
      pageSize: 7, 
      group: { 
       field: "category", 
       aggregates: [ 
        { field: "category", aggregate: "count" } 
       ] 
      } 
     }, 
     sortable: true, 
     scrollable: false, 
     pageable: true, 
     editable: true, 
     columns: [ 
      { field: "category", title: "Categoría", aggregates: ["count"], groupFooterTemplate: "Total: #=count#" }, 
      { field: "subCategory", title: "Subcategoria" }, 
      { command: "destroy", title: "", width: "150px" } 

     ] 
    }); 
} 

有我添加字段後採取行動。問題是,我想後之後,該網格重置刷新它並插入另一值我嘗試使用下一個命令:

$("#lstCategory").empty(); // this one dissapear kendo grid 
    $('#lstCategory').data('kendoGrid').refresh(); 
    $('#lstCategory').data().kendoGrid.destroy(); 

但他們沒有沖洗後後,我的劍道,有什麼可以是問題嗎?

更新:

嘗試爲恐懼海盜回答:

後的行動後,我送這樣的:

var grid = $("#lstCategory").getKendoGrid(); 
        var info = refeshInfoFromServer(); 
        grid.dataSource.data(info); 

function refeshInfoFromServer() { 
    return $("#lstCategory").data("kendoGrid").dataSource.read(); 
} 

這似乎是工作,但我的網頁會卡在裝載。 Google Chrome Inspector返回

kendo.all.min.js:11 Uncaught TypeError: e.slice is not a function

+0

片引發錯誤。您需要定義數據來自哪些屬性。如果您沒有指定它使用某個默認值。 http://docs.telerik.com/kendo-ui/api/javascript/data/datasource – Ademar

+0

這不是我所建議的......你需要重新填充服務器中的信息*但是你第一次使用它*。沒有辦法info = grid.dataSource.read(),因爲read()方法返回一個Promise * not *數據。所以,你現在正在做的是將dataSource的數據設置爲Promise ...,它甚至不能遠程工作,這就是爲什麼你得到了切片錯誤......當切片在Promise上被調用時而不是合法的數據陣列。您需要向我們展示信息是如何填充的。 –

回答

1

想要在發佈後重新從服務器讀取網格的數據嗎?

grid.refresh()只會將網格重新綁定到當前數據源......它不會強制底層數據源從服務器重新讀取。 http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#methods-refresh

通常要做到強制電網再次命中服務器什麼是使用底層數據源的read()方法(http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-read),即:

$("#lstCategory").data("kendoGrid").dataSource.read(); 

但是,這隻會打服務器如果dataSource綁定到遠程讀取端點,否則它只是重新讀取本地數組......您的dataSource的數據來自稱爲「info」的神祕變量,這可能是一個已經獲取的數組,是的?

在這種情況下,您需要先強制信息數組進行刷新(通過做任何事情再次填充它)然後用新數據更新網格的dataSource,然後重新綁定網格。

事情是這樣的:

// Do Post or whatever... 
var grid = $("#lstCategory").getKendoGrid(); 
info = refeshInfoFromServer(); 
grid.dataSource.data(info); 
//grid.refresh(); // NOTE: not necessary as .data(info) will automatically do rebind to the grid it belongs to.automatically do this. 

工作演示用假數據:當你的方案不匹配反對你從服務器或從對象定列表獲得http://dojo.telerik.com/@Stephen/aGAQo

+0

我嘗試作爲您的回答,但我遇到了問題,我將其發佈在我的問題中,請您仔細閱讀它? –

+0

我得到它的工作,我發佈答案基於我自己的數據 –