Commit fc8490c1 authored by William Arsac's avatar William Arsac Committed by Florent POITTEVIN
Browse files

perf: add optional preload of rows for pagination

parent 06a3eaf2
......@@ -81,6 +81,7 @@
[listCdkDropListId]="foldersWithIntermediateFoldersObs | async"
[draggablePreviewColumn]="'fileName'"
[draggablePreviewMatIcon]="'insert_drive_file'"
[preloadRowsForPage]="true"
>
</dlcm-shared-data-table>
</div>
......
......@@ -84,7 +84,7 @@
</dlcm-shared-paginator>
</div>
<p-table [columns]="columns"
[value]="datas"
[value]="preloadRowsForPage ? datasForPage : datas"
selectionMode="single"
[autoLayout]="true"
[responsive]="true"
......@@ -239,6 +239,7 @@
(onEnter)="showDetail(rowData)"
(click)="showDetail(rowData)"
(cdkDragStarted)="dragStart($event)"
[hidden]="isEmptyData(rowData)"
>
<div *cdkDragPreview>
<mat-icon *ngIf="!(draggablePreviewMatIcon | isNullOrUndefined)"
......
......@@ -90,8 +90,17 @@ export class SharedDataTablePresentational<TResource extends BaseResource> exten
return this._datas;
}
private _datasForPage: TResource[];
get datasForPage(): TResource[] {
return this._datasForPage;
}
trackByFunction: TrackByFunction<TResource> = (index: number, item: TResource) => index;
@Input()
preloadRowsForPage: boolean = false;
@Input()
isMultiSelectable: boolean = false;
......@@ -257,6 +266,9 @@ export class SharedDataTablePresentational<TResource extends BaseResource> exten
if (changes.queryParameters || changes.actions || changes.datas) {
this.computeContext();
}
if (changes.queryParameters || changes.datas) {
this.computeDatasForPage();
}
}
private computeContext(): void {
......@@ -270,6 +282,13 @@ export class SharedDataTablePresentational<TResource extends BaseResource> exten
});
}
private computeDatasForPage(): void {
const count = this.queryParameters && this.queryParameters.paging ? this.queryParameters.paging.pageSize : 0;
const defaultValue = this._getEmptyData();
this._datasForPage = new Array(count || 0).fill(defaultValue);
(this._datas || []).forEach((value, index) => this._datasForPage[index] = value);
}
private resetCounterItemSelectedOnCurrentPage(): void {
this.multiSelectionValueOnCurrentPageCounter = 0;
}
......@@ -626,6 +645,23 @@ export class SharedDataTablePresentational<TResource extends BaseResource> exten
}
return action.disableCondition(rowData);
}
// Empty data
private static readonly _emptyData: {} = {};
static isEmptyData(value: any): boolean {
return this._emptyData === value;
}
private _getEmptyData(): {} {
return SharedDataTablePresentational._emptyData;
}
isEmptyData(value: any): boolean {
return SharedDataTablePresentational.isEmptyData(value);
}
}
class Context {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment