David Munsa
David Munsa

Reputation: 893

kendo ui grid with angular 2 and async datasource

iam trying to generate a grid which loaded by ajax (JSON from my server)

what is the simple wait to do it ?

how to i bind async json response to this grid ?

the code below is how i do it today ( hard coded )

thank u

import { Component, OnInit } from '@angular/core';
import { HttpService } from 'services/http.service'

@Component({
    selector: 'my-analytics',
    styleUrls: ['../../../node_modules/@telerik/kendo-theme-default/dist/all.css'],
    template: require('./analytics.component.html')

})
export class AnalyticsComponent implements OnInit {

    private gridData: any[] = [{
        "ProductID": 1,
        "ProductName": "Chai",
        "UnitPrice": 18.0000,
        "Discontinued": false,
        "Category": {
            "CategoryID": 1,
            "CategoryName": "Beverages",
            "Description": "Soft drinks, coffees, teas, beers, and ales"
        }
    }, {
        "ProductID": 2,
        "ProductName": "Chang",
        "UnitPrice": 19.0000,
        "Discontinued": false,
        "Category": {
            "CategoryID": 1,
            "CategoryName": "Beverages",
            "Description": "Soft drinks, coffees, teas, beers, and ales"
        }
    }, {
        "ProductID": 3,
        "ProductName": "Aniseed Syrup",
        "UnitPrice": 10.0000,
        "Discontinued": false,
        "Category": {
            "CategoryID": 2,
            "CategoryName": "Condiments",
            "Description": "Sweet and savory sauces, relishes, spreads, and seasonings"
        }
    }];

    constructor(private http_service: HttpService) { }

    ngOnInit() {

    }
}

Upvotes: 1

Views: 2160

Answers (2)

RaghuS
RaghuS

Reputation: 103

u can try like this by using subsribe

       this.http.get(this.url)
        .map(response => response.json())
        .subscribe(result => {
             this.gridData= result


        },
             err => console.log(err)
        );

Upvotes: 1

Petyo Ivanov
Petyo Ivanov

Reputation: 1137

You can use the async pipe for that purpose. Check the respective Data Binding help article.

Upvotes: 0

Related Questions