在通过http加载数据之前,angular2用于angular2 kendo ui网格

时间:2016-10-06 10:46:14

标签: angular kendo-ui kendo-ui-angular2

我使用angular2 kendo ui网格并通过http调用将数据绑定到网格

在http调用返回数据之前我需要显示忙指示符而不显示网格标题直到分配数据。如何实现此

谢谢, Raghu s

3 个答案:

答案 0 :(得分:3)

我通过在HTML模板中声明以下内容来实现此目的。

在网格上方添加一个新div,其中包含加载网格时的条件加载文本:

<div *ngIf="loading == true" class="loader">Loading..</div>

在网格中添加div包装器,以便在完成加载时加载:

<div *ngIf="loading == false">
  <kendo-grid [data]="view1">
  <kendo-grid>
</div>

app.component.ts

export class AppComponent{
    private loading: boolean = true;

constructor(private http: Http      
    ) {
        http.get('/api/Data')
            .map(response => response.json())
            .subscribe(result => {

                this.loading = false;
                this.view1 = result;
                this.loadProducts();
            },
                 err => console.log(err)
            );
    }
}

答案 1 :(得分:2)

您可以使用有条件添加以下元素之一 -

<span class="k-icon k-i-loading"></span>
<span class="k-icon k-i-loading" style="font-size: 64px;"></span>
<span class="k-icon k-i-loading" style="color: limegreen;"></span>

正如我所做的那样

<div *ngIf="!this.gridData">
    <span class="k-icon k-i-loading" style="font-size: 64px;"></span>
</div>

如此处http://www.telerik.com/kendo-angular-ui/components/styling/icons/#toc-flipping

所述

答案 2 :(得分:1)

从3.1.0版开始,Kendo UI Grid for Angular具有内置的加载指示器功能。

请参见sample documentation here

基本前提是设置[loading] property of the kendo-grid

<kendo-grid 
  [loading]="yourService.loading"
  ...
>
<!-- Grid column configuration -->
</kendo-grid>

然后在服务类中,根据对远程数据源的查询状态,将布尔值加载变量设置为true或false:

export abstract class NorthwindService extends BehaviorSubject<GridDataResult> {
    public loading: boolean;

    private BASE_URL = 'https://odatasampleservices.azurewebsites.net/V4/Northwind/Northwind.svc/';

    constructor(
        private http: HttpClient,
        protected tableName: string
    ) {
        super(null);
    }

    public query(state: any): void {
        this.fetch(this.tableName, state)
            .subscribe(x => super.next(x));
    }

    protected fetch(tableName: string, state: any): Observable<GridDataResult> {
        const queryStr = `${toODataString(state)}&$count=true`;
        this.loading = true;

        return this.http
            .get(`${this.BASE_URL}${tableName}?${queryStr}`)
            .pipe(
                map(response => (<GridDataResult>{
                    data: response['value'],
                    total: parseInt(response['@odata.count'], 10)
                })),
                tap(() => this.loading = false)
            );
    }
}