mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
#478 pagination improvements
- update page summary only on data change (performance and presentation improvements)
This commit is contained in:
@@ -15,6 +15,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { Subject } from 'rxjs/Rx';
|
||||||
|
|
||||||
export interface PaginationProvider {
|
export interface PaginationProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,4 +46,9 @@ export interface PaginationProvider {
|
|||||||
* or if there was no maxItems parameter the default value is 100.
|
* or if there was no maxItems parameter the default value is 100.
|
||||||
*/
|
*/
|
||||||
maxItems: number;
|
maxItems: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event that is emitted every time data is loaded.
|
||||||
|
*/
|
||||||
|
dataLoaded: Subject<any>;
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
import { PaginationProvider } from './pagination-provider';
|
import { PaginationProvider } from './pagination-provider';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -24,10 +24,12 @@ import { PaginationProvider } from './pagination-provider';
|
|||||||
templateUrl: './pagination.component.html',
|
templateUrl: './pagination.component.html',
|
||||||
styleUrls: ['./pagination.component.css']
|
styleUrls: ['./pagination.component.css']
|
||||||
})
|
})
|
||||||
export class PaginationComponent {
|
export class PaginationComponent implements OnInit {
|
||||||
|
|
||||||
DEFAULT_PAGE_SIZE: number = 20;
|
DEFAULT_PAGE_SIZE: number = 20;
|
||||||
|
|
||||||
|
private _summary: string = '';
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
supportedPageSizes: number[] = [5, 10, 20, 50, 100];
|
supportedPageSizes: number[] = [5, 10, 20, 50, 100];
|
||||||
|
|
||||||
@@ -52,13 +54,7 @@ export class PaginationComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get summary(): string {
|
get summary(): string {
|
||||||
let from = this.provider.skipCount;
|
return this._summary;
|
||||||
if (from === 0) {
|
|
||||||
from = 1;
|
|
||||||
}
|
|
||||||
let to = this.provider.skipCount + this.provider.count;
|
|
||||||
let of = this.provider.totalItems;
|
|
||||||
return `${from}-${to} of ${of}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get nextPageAvail(): boolean {
|
get nextPageAvail(): boolean {
|
||||||
@@ -76,4 +72,20 @@ export class PaginationComponent {
|
|||||||
showPrevPage() {
|
showPrevPage() {
|
||||||
this.provider.skipCount -= this.provider.maxItems;
|
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}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { DatePipe } from '@angular/common';
|
import { DatePipe } from '@angular/common';
|
||||||
|
import { Subject } from 'rxjs/Rx';
|
||||||
import { ObjectUtils } from 'ng2-alfresco-core';
|
import { ObjectUtils } from 'ng2-alfresco-core';
|
||||||
import {
|
import {
|
||||||
PaginationProvider,
|
PaginationProvider,
|
||||||
@@ -51,10 +52,12 @@ export class ShareDataTableAdapter implements DataTableAdapter, PaginationProvid
|
|||||||
private _maxItems: number = this.DEFAULT_PAGE_SIZE;
|
private _maxItems: number = this.DEFAULT_PAGE_SIZE;
|
||||||
|
|
||||||
thumbnails: boolean = false;
|
thumbnails: boolean = false;
|
||||||
|
dataLoaded: Subject<any>;
|
||||||
|
|
||||||
constructor(private documentListService: DocumentListService,
|
constructor(private documentListService: DocumentListService,
|
||||||
private basePath: string,
|
private basePath: string,
|
||||||
schema: DataColumn[]) {
|
schema: DataColumn[]) {
|
||||||
|
this.dataLoaded = new Subject<any>();
|
||||||
this.rows = [];
|
this.rows = [];
|
||||||
this.columns = schema || [];
|
this.columns = schema || [];
|
||||||
this.resetPagination();
|
this.resetPagination();
|
||||||
@@ -201,7 +204,10 @@ export class ShareDataTableAdapter implements DataTableAdapter, PaginationProvid
|
|||||||
maxItems: this._maxItems,
|
maxItems: this._maxItems,
|
||||||
skipCount: this._skipCount
|
skipCount: this._skipCount
|
||||||
})
|
})
|
||||||
.subscribe(val => this.loadPage(<NodePaging>val),
|
.subscribe(val => {
|
||||||
|
this.loadPage(<NodePaging>val);
|
||||||
|
this.dataLoaded.next();
|
||||||
|
},
|
||||||
error => console.error(error));
|
error => console.error(error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user