Browse Source

Add Infinite Scroll to extensible-table

pull/23670/head
Leandro Candeias 1 year ago
parent
commit
2b744664db
  1. 5
      npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.html
  2. 19
      npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts

5
npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.html

@ -7,6 +7,11 @@
(activate)="tableActivate.emit($event)" (activate)="tableActivate.emit($event)"
(select)="onSelect($event)" (select)="onSelect($event)"
[selected]="selected" [selected]="selected"
(scroll)="onScroll($event)"
[scrollbarV]="infiniteScroll"
[style.height]="infiniteScroll ? '300px' : 'auto'"
[loadingIndicator]="infiniteScroll && isLoading"
[footerHeight]="infiniteScroll ? false : 50"
> >
@if(selectable) { @if(selectable) {
<ngx-datatable-column [width]="50" [sortable]="false" [canAutoResize]="false" [draggable]="false" [resizeable]="false"> <ngx-datatable-column [width]="50" [sortable]="false" [canAutoResize]="false" [draggable]="false" [resizeable]="false">

19
npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts

@ -118,6 +118,10 @@ export class ExtensibleTableComponent<R = any> implements OnChanges, AfterViewIn
@Input() selected: any[] = []; @Input() selected: any[] = [];
@Output() selectionChange = new EventEmitter<any[]>(); @Output() selectionChange = new EventEmitter<any[]>();
@Input() infiniteScroll = false;
@Input() isLoading = false;
@Output() loadMore = new EventEmitter<void>();
hasAtLeastOnePermittedAction: boolean; hasAtLeastOnePermittedAction: boolean;
readonly propList: EntityPropList<R>; readonly propList: EntityPropList<R>;
@ -247,10 +251,23 @@ export class ExtensibleTableComponent<R = any> implements OnChanges, AfterViewIn
this.selectionChange.emit(selected); this.selectionChange.emit(selected);
} }
onScroll(scrollEvent) {
if (
this.infiniteScroll &&
!this.isLoading &&
scrollEvent?.target?.offsetHeight + scrollEvent?.target?.scrollTop >=
scrollEvent?.target?.scrollHeight - 1
) {
this.loadMore.emit();
}
}
ngAfterViewInit(): void { ngAfterViewInit(): void {
this.list?.requestStatus$?.pipe(filter(status => status === 'loading')).subscribe(() => { if (!this.infiniteScroll) {
this.list?.requestStatus$?.pipe(filter(status => status === 'loading')).subscribe(() => {
this.data = []; this.data = [];
this.cdr.markForCheck(); this.cdr.markForCheck();
}); });
}
} }
} }

Loading…
Cancel
Save