import { Component, OnInit } from '@angular/core'; import { KGridHelper } from '../../../../_helpers/k-grid.class'; import { NotificationService } from '../../../../_services/notification.service'; import { AuthenticationService } from '../../../../_services/authentication.service'; import { SortDescriptor, orderBy } from '@progress/kendo-data-query'; import { PageChangeEvent } from '@progress/kendo-angular-grid'; import { CoustomerServices } from '../../coustome-services'; import { LocalService } from '../../../../_services/local.service'; @Component({ selector: 'app-contrect-list', templateUrl: './contrect-list.component.html', }) export class ContrectListComponent implements OnInit { public kGrid: KGridHelper = new KGridHelper(); constructor(public _notificationService: NotificationService, public _coustomerServices: CoustomerServices, public _authenticationService: AuthenticationService, public _localService: LocalService) { } ngOnInit() { this.initializeProps(); this.getContrectList(); } private initializeProps() { this.kGrid.loading = false; this.kGrid.pageSize = 20; this.kGrid.pageSizes = [20, 50, 100]; } public getContrectList() { this.kGrid.loading = true; this._coustomerServices.getContrectList(this.kGrid.skip, this.kGrid.pageSize, this.kGrid.searchQuery, this.kGrid.hfId, this.kGrid.geoLvlCode, this.kGrid.hfType, this.kGrid.stockId).subscribe( (response: any) => { this.kGrid.data = []; this.kGrid.data = response.DtlList; this.kGrid.totalRecords = response.TotalCount; this.kGrid.gridView = { data: this.kGrid.data, total: this.kGrid.totalRecords }; this.kGrid.loading = false; console.log(this.kGrid.gridView); }, err => this.handleError(err) ); } public sortChange(sort: SortDescriptor[]): void { if (sort[0].field == 'asd') { return; } this.kGrid.sort = sort; this.sortData(); } private sortData() { this.kGrid.gridView = { data: orderBy(this.kGrid.data, this.kGrid.sort), total: this.kGrid.totalRecords }; } public pageChange(event: PageChangeEvent): void { this.kGrid.skip = event.skip; this.getContrectList(); } private handleError(err: any) { this.kGrid.loading = false; if (err.status == 403) { this._authenticationService.logout(); } } onBinClick(aid: number) { alert(aid); } public changePagesize(value: any) { this.kGrid.pageSize = +value; this.kGrid.skip = 0; this.getContrectList(); } }