projects/k-components/src/lib/components/datapager/datapager.component.ts
selector | wm-data-pager-helper |
templateUrl | ./datapager.component.html |
Properties |
|
Methods |
Inputs |
Accessors |
constructor()
|
pageSize | |
Type : number
|
|
Default value : 5
|
|
source | |
filterCollectionIfRequired | ||||||
filterCollectionIfRequired(skip: number)
|
||||||
Parameters :
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
pageChange | ||||||
pageChange(pageChangeEvent: PageChangeEvent)
|
||||||
Parameters :
Returns :
void
|
Public outputCollection |
Type : GridDataResult
|
Default value : { data: [], total: 0 }
|
pageSize |
Type : number
|
Default value : 5
|
Decorators :
@Input()
|
Public skip |
Type : number
|
Default value : 0
|
Public sourceChanged |
Type : function
|
Private sourceCollection |
Type : Array<any>
|
source | ||||||
setsource(value: Array
|
||||||
Parameters :
Returns :
void
|
import { Component, Input } from '@angular/core';
import { GridDataResult, PageChangeEvent } from '@progress/kendo-angular-grid';
@Component({
selector: 'wm-data-pager-helper',
templateUrl: './datapager.component.html',
})
export class DataPagerHelper {
private sourceCollection: Array<any>;
@Input() pageSize = 5;
@Input()
set source(value: Array<any>) {
this.sourceCollection = value;
this.filterCollectionIfRequired(0);
if (this.sourceChanged) {
this.sourceChanged();
}
}
public skip = 0;
public outputCollection: GridDataResult = { data: [], total: 0 };
public sourceChanged: () => void;
constructor() {}
ngOnInit(): void {
this.filterCollectionIfRequired(0);
}
filterCollectionIfRequired(skip: number): void {
this.skip = skip;
if (this.sourceCollection && this.sourceCollection.length > 0) {
this.outputCollection = {
data: this.sourceCollection.slice(skip, skip + this.pageSize),
total: this.sourceCollection.length,
};
} else if (this.sourceCollection && this.sourceCollection.length === 0) {
this.outputCollection = {
data: [],
total: 0,
};
}
}
pageChange(pageChangeEvent: PageChangeEvent): void {
this.filterCollectionIfRequired(pageChangeEvent.skip);
}
}
<span></span>