如何使用 Angular Kendo UI 刷新网格数据源 [英] How can I refresh a grid data source using angular Kendo UI
问题描述
我正在使用 Angular Kendo UI 项目将 Telerik Kendo 网格与 Angular 相结合.
I am combining Telerik Kendo grid with Angular using the Angular Kendo UI project.
我有以下标记:
<div kendo-grid="" k-options="thingsOptions" style="height: 600px;" />
以及我的控制器中的以下代码:
and the following code in my controller:
$scope.thingsOptions = {
dataSource: {
type: "json",
transport: {
read: "/OM/om/getAssets",
dataType: "json"
},
schema: {
model: {
id: "ProductID",
...
这一切正常,但是我想从我的控制器强制刷新我的网格的数据源.类似的东西
This all works fine however I would like to force a data source refresh of my grid from my controller. something like
$scope.getTasks = function() {
$scope.thingsOptions.dataSource.read();
};
这可以从控制器上做到吗?我总是可以做类似的事情
Is this possible to do from the controller? I could always do something like
$("#taskGrid").data("kendoGrid").dataSource.read();
在我的控制器中.但是必须从我的控制器中选择一个 HTML 元素似乎有点错误.
In my controller. But it seems a bit wrong to have to select a HTML element from my controller.
推荐答案
只需将作用域变量传递给指令,然后在您的控制器内部,您就可以使用该变量来调用您需要的任何小部件方法.
Just pass in a scope variable to the directive, then inside of your controller you can use the variable to call whatever widget methods you need.
<div kendo-grid="grid" ...></div>
<script>
...
$scope.getTasks = function() {
// scope.grid is the widget reference
$scope.grid.refresh();
}
...
</script>
参考:http://blogs.telerik.com/kendoui/posts/14-02-26/a-few-angular-kendo-ui-best-practices
这篇关于如何使用 Angular Kendo UI 刷新网格数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!