0
votes

I have an Angular app that retrieves my data from the server and would like to use the results to populate a kendo grid. I have tried to create a kendo.data.DataSource but can not get the grid to populate. Below is what I am trying.

    $scope.surchargeGridOptions = {
        dataSource: {
            pageSize: 15,
            autoSync: true,
            autoBind: false,
            data: $scope.model.dataSource,
    }


    $scope.getWaivers = function () {
            waiverService.getCustomers($scope.model.customer.CustomerID).then(function (result) {
            $scope.model.waivers = result.data;
            $scope.model.dataSource = new kendo.data.DataSource({
                data: $scope.model.waivers,
                });
            $scope.model.dataSource.read();
      });
   };

Is it possible to do this and how should I go about it?

2
Also, are you aware that the closing brace of your options is missing? - hally9k

2 Answers

0
votes

The data source object in your options has a data property that only requires a reference to a plain array, not an entire kendo data source.

You should use k-data-source to reference your data...

<kendo-grid k-data-source="myData"></kendo-grid>

... and you don't strictly need a kendo data source to get it working...

$scope.myData = [
 { name: 'a', number: 1 },
 { name: 'b', number: 1 },
 { name: 'c', number: 1 },
 { name: 'd', number: 1 }
];

.. If you have dynamic data then a kendo observable array would be best practice.

Here is a code pen example.

0
votes

Front Html Page having Grid option

<div kendo-grid="ListGrid" options="ListOptions" k-rebind="ListOptions" class="k-grid-content-border"></div>


 function GridColumn() {
        return [{
            field: 'name',
            template: "<a ng-click='ToList(this.dataItem)' class='cursor-pointer'>{{this.dataItem.name}}</a>",
            title: "",
            footerTemplate: "Total",
            width: 200,
            locked: true,
        }]}

$scope.ToGeo = function (item) {
        $scope.dataLoded = false;
        GetResults(function (res) {
            $scope.ListOptions.dataSource = new kendo.data.DataSource({
                data: res,
            });
            $scope.ListOptions.columns = GridColumn();
            $scope.ListGrid.refresh();
            $scope.dataLoded = true;
        })

    }

where GetResults is for API call and fetching data