Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I refresh a grid data source using angular Kendo UI

I am combining Telerik Kendo grid with Angular using the Angular Kendo UI project.

I have the following markup:

<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();

In my controller. But it seems a bit wrong to have to select a HTML element from my controller.

like image 564
David Kethel Avatar asked Feb 11 '14 06:02

David Kethel


People also ask

What is Databound event in kendo grid?

Fired when the widget is bound to data from its data source. The event handler function context (available via the this keyword) will be set to the widget instance.


2 Answers

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>

Ref: http://blogs.telerik.com/kendoui/posts/14-02-26/a-few-angular-kendo-ui-best-practices

like image 178
micjamking Avatar answered Nov 03 '22 23:11

micjamking


Your datasource must be a kendo object

$scope.thingsOptions = {
        dataSource: new kendo.data.DataSource({
                    type: "json",
                    transport: {
                        read: "/OM/om/getAssets",
                        dataType: "json"
                    },
                    schema: {
                        model: {
                            id: "ProductID",

then it is possible to call

$scope.thingsOptions.dataSource.read();
like image 26
Yakub Avatar answered Nov 03 '22 23:11

Yakub