Trackby for the bill table. This should prevent rerendering and it jumping up.
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
<h2>Bill</h2>
|
<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">
|
<ng-container matColumnDef="bill-no-title">
|
||||||
<mat-header-cell *matHeaderCellDef class="deep-purple-200 bold">Bill / KOT number</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef class="deep-purple-200 bold">Bill / KOT number</mat-header-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|||||||
@ -37,7 +37,6 @@ import { VoucherType } from './voucher-type';
|
|||||||
AsyncPipe,
|
AsyncPipe,
|
||||||
CurrencyPipe,
|
CurrencyPipe,
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
|
|
||||||
MatCheckboxModule,
|
MatCheckboxModule,
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatTableModule,
|
MatTableModule,
|
||||||
@ -64,7 +63,6 @@ export class BillsComponent implements OnInit {
|
|||||||
this.bs.loadData(data.item, data.updateTable);
|
this.bs.loadData(data.item, data.updateTable);
|
||||||
});
|
});
|
||||||
this.getPax();
|
this.getPax();
|
||||||
this.dataSource = new BillsDataSource(this.bs.dataObs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getPax(): void {
|
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 {
|
addOne(item: BillViewItem): void {
|
||||||
this.bs.addOne(item);
|
this.bs.addOne(item);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user