import { Component, OnInit } from '@angular/core'; import { KGridHelper } from '../../../../_helpers/k-grid.class'; import { NotificationService } from '../../../../_services/notification.service'; import { EmployeeServices } from '../../../employee/employee-services'; import { AuthenticationService } from '../../../../_services/authentication.service'; import { SortDescriptor, orderBy } from '@progress/kendo-data-query'; import { PageChangeEvent } from '@progress/kendo-angular-grid'; import { ExpenseServices } from '../../expense-services'; import { LocalService } from '../../../../_services/local.service'; @Component({ selector: 'app-sim-expense-list', templateUrl: './sim-expense-list.component.html', }) export class SimExpenseListComponent implements OnInit { public kGrid: KGridHelper = new KGridHelper(); constructor(public _notificationService: NotificationService, public _expenseServices: ExpenseServices, public _authenticationService: AuthenticationService, public _localService: LocalService) { } ngOnInit() { this.initializeProps(); this.getSimExpenseList(); } private initializeProps() { this.kGrid.loading = false; this.kGrid.pageSize = 20; this.kGrid.pageSizes = [20, 50, 100]; } public getSimExpenseList() { this.kGrid.loading = true; this._expenseServices.getSimExpenseList(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.getSimExpenseList(); } 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.getSimExpenseList(); } }