Skip to content

Instantly share code, notes, and snippets.

@StickNitro
Last active June 14, 2022 04:34
Show Gist options
  • Save StickNitro/5b476cd4f6218080b5438776c612631e to your computer and use it in GitHub Desktop.
Save StickNitro/5b476cd4f6218080b5438776c612631e to your computer and use it in GitHub Desktop.
mat-table with no records found display
<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>
displayedColumns = [];
dataSource = new MatTableDataSource([]);
@teolag
Copy link

teolag commented May 28, 2019

Thanks! Great gist!
You can use datasource.filteredData.length to allow usage together with the filter function in mat-table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment