如何从Angular控制器调用kendo-grid上的refresh()? [英] How to call refresh() on a kendo-grid from an Angular controller?

查看:56
本文介绍了如何从Angular控制器调用kendo-grid上的refresh()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试遵循一些有关刷新剑道网格的建议,例如

I'm attempting to follow several suggestions on refreshing a kendo-grid such as this.

关键是在html中,我拥有:

The essential is that in the html I have:

<div kendo-grid="vm.webapiGrid" options="vm.mainGridOptions">

然后在我拥有的控制器中:

Then in the controller I have:

vm.webapiGrid.refresh();

注意:我使用的是ControllerAs语法,所以我使用的是"vm"而不是$ scope.

Note: I'm using the ControllerAs syntax so I am using "vm" rather than $scope.

我的问题是"vm.webapiGrid"未定义.这似乎很简单,但我不确定为什么未定义.

My problem is that "vm.webapiGrid" is undefined. This seems so straightforward, but I'm not sure why it is undefined.

推荐答案

找到了答案.刷新我所读过的数据源的另一种方法是执行以下操作:

Found the answer. One other method of refreshing the datasource I read about was to do something like:

vm.mainGridOptions.datasource.transport.read();

这对我不起作用,因为读取"未定义.查看我的数据源定义,我看到了原因,读取需要一个参数(在本例中为"e"):

This wasn't working for me as "read" was undefined. Looking at my datasource definition, I saw the reason, read needs a parameter (in this case "e"):

    vm.mainGridOptions = {
        dataSource: {
            transport: {
                read: function (e) {
                    task.getAllTasks(vm.appContext.current.contextSetting).
                        then(function (data) {
                            e.success(data);
                        });
                },
            }
        },

为解决此问题,我将"e"保存在我的范围内,然后在需要刷新时重新使用它:

To solve, I saved "e" in my scope and then reused it when I wanted to refresh:

    vm.mainGridOptions = {
        dataSource: {
            transport: {
                read: function (e) {
                    task.getAllTasks(vm.appContext.current.contextSetting).
                        then(function (data) {
                            e.success(data);
                            vm.optionCallback = e;
                        });
                },
            }
        },

然后:

if (vm.optionCallback !== undefined) {
   vm.mainGridOptions.dataSource.transport.read(vm.optionCallback);
}

问题解决了(我希望).

Problem solved (I hope).

这篇关于如何从Angular控制器调用kendo-grid上的refresh()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆