#478 pagination improvements

- update page summary only on data change (performance and presentation
improvements)
This commit is contained in:
Denys Vuika
2016-10-28 14:57:03 +01:00
parent cf8ada62c0
commit 6873fc01bc
3 changed files with 35 additions and 10 deletions

View File

@@ -15,6 +15,8 @@
* limitations under the License.
*/
import { Subject } from 'rxjs/Rx';
export interface PaginationProvider {
/**
@@ -44,4 +46,9 @@ export interface PaginationProvider {
* or if there was no maxItems parameter the default value is 100.
*/
maxItems: number;
/**
* An event that is emitted every time data is loaded.
*/
dataLoaded: Subject<any>;
}

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Component, Input } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import { PaginationProvider } from './pagination-provider';
@Component({
@@ -24,10 +24,12 @@ import { PaginationProvider } from './pagination-provider';
templateUrl: './pagination.component.html',
styleUrls: ['./pagination.component.css']
})
export class PaginationComponent {
export class PaginationComponent implements OnInit {
DEFAULT_PAGE_SIZE: number = 20;
private _summary: string = '';
@Input()
supportedPageSizes: number[] = [5, 10, 20, 50, 100];
@@ -52,13 +54,7 @@ export class PaginationComponent {
}
get summary(): string {
let from = this.provider.skipCount;
if (from === 0) {
from = 1;
}
let to = this.provider.skipCount + this.provider.count;
let of = this.provider.totalItems;
return `${from}-${to} of ${of}`;
return this._summary;
}
get nextPageAvail(): boolean {
@@ -76,4 +72,20 @@ export class PaginationComponent {
showPrevPage() {
this.provider.skipCount -= this.provider.maxItems;
}
ngOnInit() {
this.provider.dataLoaded.subscribe(() => {
this.updateSummary();
});
}
private updateSummary() {
let from = this.provider.skipCount;
if (from === 0) {
from = 1;
}
let to = this.provider.skipCount + this.provider.count;
let of = this.provider.totalItems;
this._summary = `${from}-${to} of ${of}`;
}
}