Table
Angular Material Table presents data in a structured grid format, making it easy to read and compare information. Columns can be sorted from their headers, rows can be filtered down or selected, the header can stay in place while the rows scroll under it, and a footer can close the grid off. BuilderKit restyles the headers, the rows and the cell spacing so the mat-table component matches the rest of the design system.
Long tables are usually cut into pages by the paginator component, which sits under the table and drives the same data source.
Example
A table with filtering, row selection, sortable columns, grouped headers, a footer and a paginator, all driven by one MatTableDataSource.
| Item | Description | ||||
|---|---|---|---|---|---|
ID | Pos. | Name | Progress | Fruit | |
| 1 | 1 | Amelia V. | 49% | pineapple | |
| 2 | 2 | Jasper V. | 10% | lychee | |
| 3 | 3 | Atticus A. | 66% | lychee | |
| 4 | 4 | Atticus A. | 60% | kiwi | |
| 5 | 5 | Olivia A. | 65% | peach | |
| Please note that the cost of items displayed are completely and totally made up. | |||||
| The items are not for sale and are not available for purchase. | |||||
<table mat-table [dataSource]="dataSource" matSort>
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Name</th>
<td mat-cell *matCellDef="let row">{{ row.name }}</td>
</ng-container>
<!-- Progress Column -->
<ng-container matColumnDef="progress">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Progress</th>
<td mat-cell *matCellDef="let row">{{ row.progress }}%</td>
</ng-container>
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table>
<mat-paginator [pageSizeOptions]="[5, 10, 25]" />Table with a sticky header
sticky: true on matHeaderRowDef pins the header to the top of the scroll container while the rows move under it, so the column names are still readable far down a long list.
| ID | Name | Fruit |
|---|---|---|
| 1 | Amelia V. | pineapple |
| 2 | Jasper V. | lychee |
| 3 | Atticus A. | lychee |
| 4 | Atticus A. | kiwi |
| 5 | Olivia A. | peach |
| 6 | Isla C. | pomegranate |
| 7 | Charlotte A. | pomegranate |
| 8 | Jack A. | kiwi |
| 9 | Asher A. | pomegranate |
| 10 | Arthur J. | kiwi |
| 11 | Levi I. | lime |
| 12 | Theodore V. | lychee |
| 13 | Amelia A. | mango |
| 14 | Isla M. | lychee |
| 15 | Jasper I. | lime |
| 16 | Thomas J. | pineapple |
| 17 | Arthur A. | blueberry |
| 18 | Asher T. | kiwi |
| 19 | Isla E. | peach |
| 20 | Jasper O. | lychee |
<div class="max-h-72 overflow-auto">
<!-- Sticky header cells carry the page surface so rows do not show through them -->
<table class="[&_.mat-mdc-header-cell]:bg-neutral-2 dark:[&_.mat-mdc-header-cell]:bg-neutral-1" mat-table [dataSource]="dataSource">
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>Name</th>
<td mat-cell *matCellDef="let row">{{ row.name }}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table>
</div>