|
<ejs-grid #grid [dataSource]='data | async' allowPaging=true (dataStateChange)='dataStateChange($event)' (beforeDataBound)='beforeDataBound($event)' (actionFailure)='fail($event)' allowGrouping=true>
<e-columns>
<e-column field="OrderID" headerText="Order ID" width="130" isPrimaryKey='true'></e-column>
<e-column field="CustomerID" headerText="Customer ID" width="150"></e-column>
<e-column field="Freight" headerText="Freight" width="120" format='C2'></e-column>
</e-columns>
</ejs-grid> |
|
ngOnInit() {
this.pageOptions = { pageSize: 10, pageCount: 4 };
let state = { skip: 0, take: 10 };
this.service.execute(state);
}
public beforeDataBound(): void {
let fn = () => {
this.grid.showSpinner();
this.grid.off('toolbar-refresh', fn);
};
this.grid.on('toolbar-refresh', fn);
} |
|
[order.service.ts]
...
@Injectable()
export class OrdersService extends Subject<DataStateChangeEventArgs> {
private BASE_URL = 'https://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/Orders';
constructor(private http: Http) {
super();
}
public execute(state: any): void {
this.getData(state).subscribe(x => super.next({})); //returning empty object
}
...
} |
|
[async-pipe.component.ts]
...
export class AsyncPipeComponent {
public data: Observable<DataStateChangeEventArgs>;
public pageOptions: Object;
public state: DataStateChangeEventArgs;
public isInitialLoad: boolean = false; //creating boolean variable for preventing spinner when receiving empty object
@ViewChild('grid')
public grid: GridComponent;
...
public load(args:any):void{
this.isInitialLoad = true;
}
public beforeDataBound(e): void {
let fn = () => {
this.grid.showSpinner();
this.grid.off('toolbar-refresh', fn);
if( !this.isInitialLoad && e.result.length == 0)
{
this.grid.hideSpinner(); //hide spinner
}
this.isInitialLoad = false;
};
this.grid.on('toolbar-refresh', fn);
}
} |