MAT-TABLE too slow to load when the column definitions are specified dynamically
Bug, feature request, or proposal:
Slowness
What is the expected behavior?
Expecting to display mat-table with 500 records in a second
What is the current behavior?
Taking 6 seconds to load 500 records in the below scenario
What are the steps to reproduce?
I have a table (with 25 - 30 columns) in my application whose columns are dynamically formed. We have a json array which contains the column definiotions (i.e., columnNames). Using this json array, columns are dynamically formed as mentioned below.
<.ng-container *ngFor="let column of columnNames" matColumnDef={{column.ColumnName}}> <.mat-header-cell mat-sort-header >{{ column.ColumnHeader }}<./mat-header-cell> <.mat-cell *matCellDef="let row"> {{ row[column.ColumnName] }}<./mat-cell> <./ng-container>
In this case, it is taking 5 to 6 seconds to display the data.
But when we mention the column definitions hard-coded (without ngfor) as mentioned below, it is not taking more than 1.5 seconds to load the same number of columns. But our requirement is to load the columns dynamically
<.ng-container matColumnDef='column1'> <.mat-header-cell mat-sort-header >column1<./mat-header-cell> <.mat-cell *matCellDef="let row"> {{ row[column1] }}<./mat-cell> <./ng-container> .. .. upto <.ng-container matColumnDef='column25'> <.mat-header-cell mat-sort-header >column25<./mat-header-cell> <.mat-cell *matCellDef="let row"> {{ row[column25] }}<./mat-cell> <./ng-container>
Note : We have only 500 records in the datasource
What is the use-case or motivation for changing an existing behavior?
As mentioned above, our requirement is to load the columns dynamically
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular CLI: 1.7.3 Node: 8.9.4 OS: win32 x64 Angular: 5.2.9
@angular/material: 5.2.4
Is there anything else we should know?
It would be great if someone can suggest me the best way to load columns dynamically.
Thanks.
Could you try angular material 6 beta? Maybe it got faster.
Else maybe some features from AngularJS Material should be ported to angular material. For example Virtual Repeat: https://material.angularjs.org/latest/demo/virtualRepeat
Have you tried placing a trackBy on your ngFor columnNames?
I'm experiencing a similar issue, even with the latest beta, 6.0.0-beta.6 and with trackBy set.
~230 rows, enabling additional 7 columns to 4 already rendered takes chrome about 120seconds. Firefox is much faster and does it in about tenth of the time (~15sec). All columns have inputs.
The number of columns and their definitions are set on the fly because they are back-end dependent.
Can you do an analysis of this loading ? Via the developper console or other tools ?
Or even a stackblitz reproduction?
@willshowell @Eddygn trackBy did not show any difference in the performance.
@willshowell I will try to give you a stackblitz reproduction.
Please re-open the issue with a reproduction in StackBlitz so we can dive into the issue and see what performance improvements are possible.
@andrewseguin
Here is the stackblitz reproduction - https://stackblitz.com/edit/angular-8wdr1m-q5qy7e
Just click a page number in the pagination and try to navigate among the pages. We can feel the delay up to 2 seconds. Actually in my application since I have 25 columns the delay is around 5 seconds. Although it is happening when the page size is higher like 100.
Please let us know your comments.
I hope we can reopen this ticket now?
Have you tried using a custom Data Source? I'd guess that MatTableDataSource isn't the fastest choice.
I'm not aware of custom data source. Can you please try to change it in the stackblitz if possible.
The same data is working blazing speed in jquery datatable (even when the page size is 100 and the number of columns is 35) in our old asp.net application.
Do I need to create a new issue to reopen this?
I have seen many issues with zone.js and the same behavior on github.
Have you the same issue with a build prod ? Because in others threads the problem is only in dev and vanish with build prod.
Yes. we are facing the issue in --prod build only.
@jayakrishna-v I suspect that creating 800 tooltips for each render might be the reason ;)
Here's a speed comparison of using the table without tooltips on every cell: https://stackblitz.com/edit/angular-8wdr1m-6xjchu?file=app/table-pagination-example.html
@andrewseguin Yes, removing the mattooltip certainly made the table faster. But still it is a bit slow when the page size is 100. Anyway thanks for identifying the root cause of the slowness.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.