Last active
June 14, 2022 04:34
-
-
Save StickNitro/5b476cd4f6218080b5438776c612631e to your computer and use it in GitHub Desktop.
mat-table with no records found display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-table class="mat-elevation-z8" [dataSource]="dataSource"> | |
<!-- columns here --> | |
<ng-container matColumnDef="noData"> | |
<mat-footer-cell *matFooterCellDef [attr.colspan]="displayedColumns.length"> | |
No records found. | |
</mat-footer-cell> | |
</ng-container> | |
<ng-container matColumnDef="loading"> | |
<mat-footer-cell *matFooterCellDef [attr.colspan]="displayedColumns.length"> | |
Loading, please wait... | |
</mat-footer-cell> | |
</ng-container> | |
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row> | |
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row> | |
<mat-footer-row *matFooterRowDef="['noData']" [hidden]="dataSource && dataSource.data.length > 0"></mat-footer-row> | |
<mat-footer-row *matFooterRowDef="['loading']" [hidden]="dataSource !== undefined"></mat-footer-row> | |
</mat-table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
displayedColumns = []; | |
dataSource = new MatTableDataSource([]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! Great gist!
You can use
datasource.filteredData.length
to allow usage together with the filter function in mat-table