diff --git a/src/components-examples/material/table/index.ts b/src/components-examples/material/table/index.ts index 3a09a7ad8df7..ef7a2c516b9d 100644 --- a/src/components-examples/material/table/index.ts +++ b/src/components-examples/material/table/index.ts @@ -6,6 +6,7 @@ export {TableFilteringExample} from './table-filtering/table-filtering-example'; export {TableFooterRowExample} from './table-footer-row/table-footer-row-example'; export {TableHttpExample} from './table-http/table-http-example'; export {TableMultipleHeaderFooterExample} from './table-multiple-header-footer/table-multiple-header-footer-example'; +export {TableMultipleRowTemplateExample} from './table-multiple-row-template/table-multiple-row-template-example'; export {TableOverviewExample} from './table-overview/table-overview-example'; export {TablePaginationExample} from './table-pagination/table-pagination-example'; export {TableRowContextExample} from './table-row-context/table-row-context-example'; diff --git a/src/components-examples/material/table/table-multiple-row-template/table-multiple-row-template-example.css b/src/components-examples/material/table/table-multiple-row-template/table-multiple-row-template-example.css new file mode 100644 index 000000000000..bdadd8bb186f --- /dev/null +++ b/src/components-examples/material/table/table-multiple-row-template/table-multiple-row-template-example.css @@ -0,0 +1,3 @@ +table { + width: 100%; +} diff --git a/src/components-examples/material/table/table-multiple-row-template/table-multiple-row-template-example.html b/src/components-examples/material/table/table-multiple-row-template/table-multiple-row-template-example.html new file mode 100644 index 000000000000..5f1ca0d36b9c --- /dev/null +++ b/src/components-examples/material/table/table-multiple-row-template/table-multiple-row-template-example.html @@ -0,0 +1,38 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
No. {{element.position}} Name {{element.name}} Weight {{element.weight}} Symbol {{element.symbol}} Secondary row for the element {{element.name}}
+
\ No newline at end of file diff --git a/src/components-examples/material/table/table-multiple-row-template/table-multiple-row-template-example.ts b/src/components-examples/material/table/table-multiple-row-template/table-multiple-row-template-example.ts new file mode 100644 index 000000000000..9baf01582c53 --- /dev/null +++ b/src/components-examples/material/table/table-multiple-row-template/table-multiple-row-template-example.ts @@ -0,0 +1,47 @@ +import {Component} from '@angular/core'; +import {MatTableDataSource, MatTableModule} from '@angular/material/table'; + +/** + * @title Table with multiple row template + */ +@Component({ + selector: 'table-multiple-row-template-example', + styleUrls: ['table-multiple-row-template-example.css'], + templateUrl: 'table-multiple-row-template-example.html', + standalone: true, + imports: [MatTableModule], +}) +export class TableMultipleRowTemplateExample { + displayedColumns: string[] = ['position', 'name', 'weight', 'symbol']; + dataSource = new MatTableDataSource(ELEMENT_DATA); +} + +export interface PeriodicElement { + name: string; + position: number; + weight: number; + symbol: string; +} + +const ELEMENT_DATA: PeriodicElement[] = [ + {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'}, + {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'}, + {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'}, + {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'}, + {position: 5, name: 'Boron', weight: 10.811, symbol: 'B'}, + {position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'}, + {position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'}, + {position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'}, + {position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'}, + {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'}, + {position: 11, name: 'Sodium', weight: 22.9897, symbol: 'Na'}, + {position: 12, name: 'Magnesium', weight: 24.305, symbol: 'Mg'}, + {position: 13, name: 'Aluminum', weight: 26.9815, symbol: 'Al'}, + {position: 14, name: 'Silicon', weight: 28.0855, symbol: 'Si'}, + {position: 15, name: 'Phosphorus', weight: 30.9738, symbol: 'P'}, + {position: 16, name: 'Sulfur', weight: 32.065, symbol: 'S'}, + {position: 17, name: 'Chlorine', weight: 35.453, symbol: 'Cl'}, + {position: 18, name: 'Argon', weight: 39.948, symbol: 'Ar'}, + {position: 19, name: 'Potassium', weight: 39.0983, symbol: 'K'}, + {position: 20, name: 'Calcium', weight: 40.078, symbol: 'Ca'}, +]; diff --git a/src/dev-app/table/table-demo.html b/src/dev-app/table/table-demo.html index 387e2ae07567..478cfd929d77 100644 --- a/src/dev-app/table/table-demo.html +++ b/src/dev-app/table/table-demo.html @@ -70,6 +70,9 @@

Table with sticky footer

Table with sticky header

+

Table with multiple rows per data item

+ +

Table with mat-text-column

diff --git a/src/dev-app/table/table-demo.ts b/src/dev-app/table/table-demo.ts index 3361a2f4fbaf..4684508bb3e7 100644 --- a/src/dev-app/table/table-demo.ts +++ b/src/dev-app/table/table-demo.ts @@ -27,6 +27,7 @@ import { TableHarnessExample, TableHttpExample, TableMultipleHeaderFooterExample, + TableMultipleRowTemplateExample, TableOverviewExample, TablePaginationExample, TableRecycleRowsExample, @@ -63,6 +64,7 @@ import {ChangeDetectionStrategy, Component} from '@angular/core'; TableFooterRowExample, TableHttpExample, TableMultipleHeaderFooterExample, + TableMultipleRowTemplateExample, TableOverviewExample, TablePaginationExample, TableRowContextExample, diff --git a/src/material/table/table.md b/src/material/table/table.md index 778e32cb806f..42fd752e6f5d 100644 --- a/src/material/table/table.md +++ b/src/material/table/table.md @@ -372,6 +372,8 @@ to resolve this. When using the `multiTemplateDataRows` directive to support multiple rows for each data object, the context of `*matRowDef` is the same except that the `index` value is replaced by `dataIndex` and `renderIndex`. + + ### Accessibility By default, `MatTable` applies `role="table"`, assuming the table's contains primarily static