剑道网格无法正确加载

时间:2018-12-01 22:10:50

标签: kendo-grid observable

问题陈述:

网格无法正确刷新。几乎没有几列需要应用css。我能理解这些列是否需要一些额外的CSS,这需要一些时间 加载网格。 我有一个约40列的剑道网格。很少有列将某些CSS应用于单元格。 我们每10秒更新一次此网格。有时,网格无法正确加载。 假设网格显示100条记录。 10秒后,如果我们获得10条新记录,则需要在网格中显示110条记录。如果修改了某些内容,我们需要对其进行更新 如果删除了某些内容,则需要从网格中删除。 网格使用可观察的数组。我知道,每当我将一个项目推入可观察数组时,就会触发一组事件。 这就是原因,在我的代码中,每当我获得不同的数据时,都会从可观察数组中删除所有项目,然后将所有内容重新添加回去。 还要注意的另一点是,当用户在网格中选择一个项目时,我们会在右侧显示一个包含一些信息的面板。 当我们每10秒钟刷新一次网格时,我们应该保持选择状态,以便用户继续做自己正在做的事情。 否则,当他刷新网格时,他需要每10秒单击该行一次,这会变得很烦人。 但是仍然有时网格无法正确加载。每当网格未正确加载时,我都会记录以下内容,并且它们不相等 $ scope.employeeDataSource.data()。length(数据源的长度) 和$ scope.kendoGrid.dataSource.total()(在网格中加载的记录) 如果我缺少一些信息,请告诉我。

如何在网格中设置数据? 即使网格加载数据的速度稍慢,也可以,但我不希望Kendo网格显示错误的数据或使网页崩溃。

//我有一个像这样定义的剑道网格

<div kendo-grid="kendoGrid" k-data-source="employeeDataSource" k-options="gridOptions" k-on-change="selectedChanged(data)"></div>

我有这样的数据源设置

$scope.employeeDataSource = new kendo.data.DataSource({ data: employeeObservable, change: (e) => { $timeout(() => { $scope.totalNumberOfRecords = $scope.kendoGrid.dataSource.total(); }); }, schema: { model: { id: "Id", fields: { EmployeeCount: { type: "number" } //few fields to follow here } } } });

重要的部分:这就是我更新网格中项目的方式。 有时它可以工作,有时网格不能正确加载。 $scope.updateGridData = (newData) => { // we remove all the items from the observable array and load the new set, all at once. employeeObservable.unbind("change"); employeeObservable.splice(0, employeeObservable.length); employeeObservable.bind("change", allocationObservableChangeEvent); //load the new set of observable array at once employeeObservable.push.apply(employeeObservable, newData) // I can also set data like this. should I use ObservableArray or set data using the kendoGrid? //$scope.kendoGrid.dataSource.data(employeeObservable); }

0 个答案:

没有答案
相关问题