|
| 1 | +import { AfterViewInit, Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core'; |
| 2 | +import { IgxGridComponent } from 'igniteui-angular'; |
| 3 | +import { RemoteService } from '../shared/remote.service'; |
| 4 | +import { Observable } from 'rxjs'; |
| 5 | + |
| 6 | +@Component({ |
| 7 | + selector: 'app-grid-remote-paging-sample', |
| 8 | + templateUrl: 'grid-remote-paging.sample.html' |
| 9 | +}) |
| 10 | +export class GridRemotePagingSampleComponent implements OnInit, AfterViewInit, OnDestroy { |
| 11 | + |
| 12 | + public page = 0; |
| 13 | + public totalCount = 0; |
| 14 | + public pages = []; |
| 15 | + public data: Observable<any[]>; |
| 16 | + public selectOptions = [5, 10, 15, 25, 50]; |
| 17 | + |
| 18 | + @ViewChild('customPager', { read: TemplateRef, static: true }) public remotePager: TemplateRef<any>; |
| 19 | + @ViewChild('grid1', { static: true }) public grid1: IgxGridComponent; |
| 20 | + |
| 21 | + private _perPage = 10; |
| 22 | + private _dataLengthSubscriber; |
| 23 | + |
| 24 | + constructor(private remoteService: RemoteService) { |
| 25 | + } |
| 26 | + |
| 27 | + public get perPage(): number { |
| 28 | + return this._perPage; |
| 29 | + } |
| 30 | + |
| 31 | + public set perPage(val: number) { |
| 32 | + this._perPage = val; |
| 33 | + this.paginate(0); |
| 34 | + } |
| 35 | + |
| 36 | + public ngOnInit() { |
| 37 | + this.data = this.remoteService.remotePagingData.asObservable(); |
| 38 | + |
| 39 | + this._dataLengthSubscriber = this.remoteService.getPagingDataLength().subscribe((data) => { |
| 40 | + this.totalCount = data; |
| 41 | + this.grid1.isLoading = false; |
| 42 | + }); |
| 43 | + } |
| 44 | + |
| 45 | + public ngOnDestroy() { |
| 46 | + if (this._dataLengthSubscriber) { |
| 47 | + this._dataLengthSubscriber.unsubscribe(); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + public ngAfterViewInit() { |
| 52 | + this.grid1.isLoading = true; |
| 53 | + this.remoteService.getPagingData(0, this.perPage); |
| 54 | + } |
| 55 | + |
| 56 | + public paginate(page: number) { |
| 57 | + this.page = page; |
| 58 | + const skip = this.page * this.perPage; |
| 59 | + const top = this.perPage; |
| 60 | + |
| 61 | + this.remoteService.getPagingData(skip, top); |
| 62 | + } |
| 63 | +} |
0 commit comments