Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(material/table): table multiple row example #27621 #29421

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components-examples/material/table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
table {
width: 100%;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource" multiTemplateDataRows>

<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef> No. </th>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation in this file and the .css one above looks off. It's probably using tabs instead of spaces.

<td mat-cell *matCellDef="let element"> {{element.position}} </td>
</ng-container>

<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>

<!-- Weight Column -->
<ng-container matColumnDef="weight">
<th mat-header-cell *matHeaderCellDef> Weight </th>
<td mat-cell *matCellDef="let element"> {{element.weight}} </td>
</ng-container>

<!-- Symbol Column -->
<ng-container matColumnDef="symbol">
<th mat-header-cell *matHeaderCellDef> Symbol </th>
<td mat-cell *matCellDef="let element"> {{element.symbol}} </td>
</ng-container>

<!-- Secondary Column -->
<ng-container matColumnDef="secondary">
<td mat-cell [attr.colspan]="displayedColumns.length"
*matCellDef="let element"> Secondary row for the element {{element.name}} </td>
</ng-container>

<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
<tr mat-row *matRowDef="let row; columns: ['secondary'];"></tr>
</table>
</div>
Original file line number Diff line number Diff line change
@@ -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<PeriodicElement>(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'},
];
3 changes: 3 additions & 0 deletions src/dev-app/table/table-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ <h3>Table with sticky footer</h3>
<h3>Table with sticky header</h3>
<table-sticky-header-example></table-sticky-header-example>

<h3>Table with multiple rows per data item</h3>
<table-multiple-row-template-example></table-multiple-row-template-example>

<h3>Table with mat-text-column</h3>
<table-text-column-example></table-text-column-example>

Expand Down
2 changes: 2 additions & 0 deletions src/dev-app/table/table-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
TableHarnessExample,
TableHttpExample,
TableMultipleHeaderFooterExample,
TableMultipleRowTemplateExample,
TableOverviewExample,
TablePaginationExample,
TableRecycleRowsExample,
Expand Down Expand Up @@ -63,6 +64,7 @@ import {ChangeDetectionStrategy, Component} from '@angular/core';
TableFooterRowExample,
TableHttpExample,
TableMultipleHeaderFooterExample,
TableMultipleRowTemplateExample,
TableOverviewExample,
TablePaginationExample,
TableRowContextExample,
Expand Down
2 changes: 2 additions & 0 deletions src/material/table/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

<!--- example(table-multiple-row-template) -->

### Accessibility

By default, `MatTable` applies `role="table"`, assuming the table's contains primarily static
Expand Down
Loading