Track by id

This commit is contained in:
Adina Țeudan 2021-10-05 21:28:41 +03:00
parent 057fbfd2a8
commit 5b6f35cbc1
4 changed files with 7 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import { EntitiesService } from './services';
import { IListable, ListingMode, ListingModes, TableColumnConfig } from './models'; import { IListable, ListingMode, ListingModes, TableColumnConfig } from './models';
export const DefaultListingServices = [FilterService, SearchService, EntitiesService, SortingService] as const; export const DefaultListingServices = [FilterService, SearchService, EntitiesService, SortingService] as const;
export const DefaultListingServicesTmp = [FilterService, SearchService, SortingService] as const;
@Directive() @Directive()
export abstract class ListingComponent<T extends IListable> extends AutoUnsubscribe implements OnDestroy { export abstract class ListingComponent<T extends IListable> extends AutoUnsubscribe implements OnDestroy {

View File

@ -26,7 +26,7 @@
<div <div
(mouseenter)="itemMouseEnterFn && itemMouseEnterFn(entity)" (mouseenter)="itemMouseEnterFn && itemMouseEnterFn(entity)"
(mouseleave)="itemMouseLeaveFn && itemMouseLeaveFn(entity)" (mouseleave)="itemMouseLeaveFn && itemMouseLeaveFn(entity)"
*cdkVirtualFor="let entity of listingComponent.sortedDisplayedEntities$ | async" *cdkVirtualFor="let entity of listingComponent.sortedDisplayedEntities$ | async; trackBy: trackById"
[ngClass]="getTableItemClasses(entity)" [ngClass]="getTableItemClasses(entity)"
[routerLink]="entity.routerLink" [routerLink]="entity.routerLink"
> >

View File

@ -65,6 +65,10 @@ export class TableComponent<T extends IListable> implements OnInit {
return this.listingComponent.tableHeaderLabel; return this.listingComponent.tableHeaderLabel;
} }
trackById(index: number, entity: T): string {
return entity.id;
}
ngOnInit(): void { ngOnInit(): void {
this.listingComponent.noContent$.subscribe(() => { this.listingComponent.noContent$.subscribe(() => {
setTimeout(() => { setTimeout(() => {

View File

@ -23,7 +23,7 @@ export class LoadingService {
return remainingLoadingTime > 0 ? this._stopAfter(remainingLoadingTime) : this._stop(); return remainingLoadingTime > 0 ? this._stopAfter(remainingLoadingTime) : this._stop();
} }
loadWhile(func: Promise<void>): void { loadWhile(func: Promise<unknown>): void {
this.start(); this.start();
func.then( func.then(