【问题标题】:Reset Kendo Grid column重置剑道网格列
【发布时间】:2016-11-15 20:10:06
【问题描述】:

我有这样的剑道网格列:

$("#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

【问题讨论】:

  • 当您的架构与您从服务器或给定对象列表中获取的对象不匹配时,将引发切片错误。您需要定义来自哪些属性数据。如果您不指定它可以使用一些默认值。 docs.telerik.com/kendo-ui/api/javascript/data/datasource
  • 这不是我的建议...您需要从服务器重新填充信息无论您第一次如何完成。 info = grid.dataSource.read() 作为 read() 方法不可能返回 Promise not 数据。因此,您现在正在做的是将 dataSource 的数据设置为 Promise ...这甚至无法远程工作,这就是您收到切片错误的原因...因为切片正在您的 Promise 上被调用推到那里而不是合法的数据数组。您首先需要向我们展示信息是如何填充的。

标签: jquery kendo-ui kendo-grid


【解决方案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();

但是,如果数据源绑定到远程读取端点,这只会命中服务器,否则它只会重新读取本地数组......您的数据源的数据来自名为“info”的神秘变量,这可能是一个已经获取的数组,是吗?

在这种情况下,您需要先强制刷新 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

【讨论】:

  • 我尝试作为您的答案,但我遇到了问题,我将其发布在我的问题中,请您查看一下吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多