import { Component, OnInit } from '@angular/core'; import { KGridHelper } from '../../../_helpers/k-grid.class'; import { NotificationService } from '../../../_services/notification.service'; import { AccountService } from '../accounts-services'; import { AuthenticationService } from '../../../_services/authentication.service'; import { SortDescriptor, orderBy } from '@progress/kendo-data-query'; import { PageChangeEvent } from '@progress/kendo-angular-grid'; import { LocalService } from '../../../_services/local.service'; @Component({ selector: 'app-list-view', templateUrl: './list-view.component.html', }) export class ListViewComponent implements OnInit { public kGrid: KGridHelper = new KGridHelper(); constructor(public _notificationService: NotificationService, public _accountService: AccountService, public _authenticationService: AuthenticationService, public _localService: LocalService) { } ngOnInit() { this.initializeProps(); this.getAccountsList(); } private initializeProps() { this.kGrid.loading = false; this.kGrid.pageSize = 20; this.kGrid.pageSizes = [20, 50, 100]; } public getAccountsList() { this.kGrid.loading = true; this._accountService.getAccountsList(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 = this.parseDate(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) ); } parseDate(list) { for (let i = 0; i < list.length; i++) { var c = 'C'; if (list[i].Balance) { if (list[i].Balance > 0) list[i].Balance = Math.abs(list[i].Balance) + '-Cr'; else list[i].Balance = Math.abs(list[i].Balance) + '-Dr'; } } return list; } 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.getAccountsList(); } 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.getAccountsList(); } }