2016-11-15 155 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

我得到它的工作,我发布答案基于我自己的数据 –