Trackby for the bill table. This should prevent rerendering and it jumping up.

This commit is contained in:
2025-08-04 15:27:21 +00:00
parent b33468a43f
commit e1cbf7ffb8
2 changed files with 8 additions and 3 deletions

View File

@ -1,6 +1,6 @@
<h2>Bill</h2>
<table mat-table #table [dataSource]="dataSource" aria-label="Elements" class="mat-elevation-z8">
<table mat-table #table [dataSource]="dataSource" class="mat-elevation-z8" [trackBy]="trackByKotProductId">
<ng-container matColumnDef="bill-no-title">
<mat-header-cell *matHeaderCellDef class="deep-purple-200 bold">Bill / KOT number</mat-header-cell>
</ng-container>

View File

@ -37,7 +37,6 @@ import { VoucherType } from './voucher-type';
AsyncPipe,
CurrencyPipe,
MatButtonModule,
MatCheckboxModule,
MatIconModule,
MatTableModule,
@ -64,7 +63,6 @@ export class BillsComponent implements OnInit {
this.bs.loadData(data.item, data.updateTable);
});
this.getPax();
this.dataSource = new BillsDataSource(this.bs.dataObs);
}
getPax(): void {
@ -188,6 +186,13 @@ export class BillsComponent implements OnInit {
}
}
trackByKotProductId(index: number, row: BillViewItem): string {
// Fallbacks in case fields are undefined/null
const kotId = row.kotId ?? '';
const productId = row.productId ?? '';
return `${kotId}_${productId}`;
}
addOne(item: BillViewItem): void {
this.bs.addOne(item);
}