I have a mat-table that has over 150 rows, which doesn't seem like much but it completely freezes the page (especially if I have the developer console open).
To set the table data I use an input getter and setter (the reason being that it then allows me to make changes in the parent component and the child component will listen.)
@Input()
get data() {
return this.dataSource;
}
set data(tableData: any) {
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
this.dataSource.data = tableData;
// moment dates cant be sorted by mat-table: this is their
// recommendation to convert it to timestamp to be sorted
// (still displays as moment date tho :D)
this.dataSource.sortingDataAccessor = (item, property) => {
switch (property) {
case 'momentDueDate': return new Date(item.momentDueDate);
default: return item[property];
}
};
}
The data itself loads relatively quick, however, as soon as I click anything on the page, the page freezes. This even includes trying to change page using mat-pagination on the table.
In my parent component, my data is created by an observable using combineLAtest like so:
this.combinedPaymentsAndfilters$ = combineLatest(
[this.combinedPaymentDetails$,
this.dateFilter$,
this.dateToFrom.asObservable(),
this.typeFilter$,
this.sortFilter$,
this.isAdmin$]).pipe(
tap(([payments, dateFilter, dateToFrom, type, sort, isAdmin]) => {
this._router.navigate(['.'], {
queryParams: {
date: dateFilter,
dateFrom: dateToFrom.date_from,
dateTo: dateToFrom.date_to,
type: type,
order: sort
},
relativeTo: this._route,
replaceUrl: true
});
}),
map(([payments, dateFilter, dateToFrom, type, sort, isAdmin]) => {
let combined = this.sortPayments(sort, payments);
if (dateFilter !== 'all') {
combined = this.filterByDate(payments, dateFilter, dateToFrom);
}
if (type !== 'all') {
combined = combined.filter(
(payment: any) => payment.paymentType === type);
}
this.paymentTitle = this.getViewValue(this.paymentTypeFilter, type);
this.dateTitle = this.getViewValue(this.dateFilterType, dateFilter);
return {
combined,
isAdmin
};
})
);
I also get the following chrome violations whilst in this component:
Other things I have tried:
So I have looked at a few similar things online, and people have recommended loading the data after the pagination etc (which you can see above I have).
Others have also recommended using AfterViewInit
, I have also tried this, but it still makes no difference.
As a way of testing whether there was something else erroring in my code, I have also limited my firestore query to only return 5 items. Once I have done this, it works absolutely fine, which tells me the issue is definitely with the amount of data I am trying to display.
Any recommendations on improving this performance as currently, its unusable for production.
EDIT - The issue only really seems to happen when the chrome console is open