Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mat-filtering/mat-sort not work correctly when use ngif in mat-table parent

Note that paging/sort not work correctly. Paging does not show the number of elements it is showing and sorting does not work, but if you delete the line in the html file *ngIf="dataSource?.filteredData.length > 0" the error is fixed. If you use filtering, it works, but it does not show the filter amount

Check the example.

https://stackblitz.com/edit/angular-wqkekh-nm3pn2?file=app/table-pagination-example.html

like image 610
avechuche Avatar asked Jun 08 '18 19:06

avechuche


Video Answer


1 Answers

This can be solved by the following strategy:

dataSource = new MatTableDataSource();

@ViewChild(MatSort, {static: false}) set content(sort: MatSort) {
  this.dataSource.sort = sort;
}

Now even if you use *ngIf, it will work.

like image 137
Rut Shah Avatar answered Sep 21 '22 16:09

Rut Shah