Skip to content

fix(material-experimental/mdc-table): Fix sticky scrolling #21211

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

Merged
merged 1 commit into from
Dec 4, 2020
Merged
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/dev-app/mdc-table/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ng_module(
],
deps = [
"//src/material-experimental/mdc-table",
"//src/material/icon",
"@npm//@angular/router",
],
)
Expand Down
2 changes: 2 additions & 0 deletions src/dev-app/mdc-table/mdc-table-demo-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
*/

import {NgModule} from '@angular/core';
import {MatIconModule} from '@angular/material/icon';
import {MatTableModule} from '@angular/material-experimental/mdc-table';
import {RouterModule} from '@angular/router';
import {MdcTableDemo} from './mdc-table-demo';

@NgModule({
imports: [
MatIconModule,
MatTableModule,
RouterModule.forChild([{path: '', component: MdcTableDemo}]),
],
Expand Down
169 changes: 141 additions & 28 deletions src/dev-app/mdc-table/mdc-table-demo.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,141 @@
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef> No. </th>
<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>

<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
<h2> Basic </h2>
<div class="example-container mat-elevation-z8">
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef> No. </th>
<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>

<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</div>

<h2> Sticky Columns </h2>
<div class="example-container mat-elevation-z8 example-sticky-columns">
<table mat-table [dataSource]="dataSource">
<!-- Name Column -->
<ng-container matColumnDef="name" sticky>
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>

<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef> No. </th>
<td mat-cell *matCellDef="let element"> {{element.position}} </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>

<!-- Star Column -->
<ng-container matColumnDef="star" stickyEnd>
<th mat-header-cell *matHeaderCellDef></th>
<td mat-cell *matCellDef="let element">
<mat-icon>more_vert</mat-icon>
</td>
</ng-container>

<tr mat-header-row *matHeaderRowDef="displayedColumns2"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns2;"></tr>
</table>
</div>

<h2> Sticky Header </h2>
<div class="example-container mat-elevation-z8 example-sticky-header">
<table mat-table [dataSource]="dataSource">

<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef> No. </th>
<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>

<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</div>

<h2> Sticky Footer </h2>
<div class="example-container mat-elevation-z8 example-sticky-footer">
<table mat-table [dataSource]="dataSource">
<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef> No. </th>
<td mat-cell *matCellDef="let element"> {{element.position}} </td>
<td mat-footer-cell *matFooterCellDef> number </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>
<td mat-footer-cell *matFooterCellDef> string </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>
<td mat-footer-cell *matFooterCellDef> number </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>
<td mat-footer-cell *matFooterCellDef> string </td>
</ng-container>

<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
<tr mat-footer-row *matFooterRowDef="displayedColumns; sticky: true"></tr>
</table>
</div>
77 changes: 77 additions & 0 deletions src/dev-app/mdc-table/mdc-table-demo.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,80 @@
.example-container {
height: 400px;
margin-bottom: 24px;
width: 550px;
max-width: 100%;
overflow: auto;
}

h2 {
margin: 0 0 16px;
}

table {
width: 800px;
}

.example-sticky-columns {
td {
background-color: white;
}

td.mat-mdc-column-star {
width: 20px;
padding-right: 8px;
}

th.mat-mdc-column-position, td.mat-mdc-column-position {
padding-left: 8px;
}

// Unlike with the classic MatTable, border-right does not work due to border-collapse.
// Using :before to not conflict with popover-edit and column-resize which use :after.
.mat-mdc-table-sticky:first-child,
.mat-mdc-table-sticky:last-child {
&::before {
background-color: #e0e0e0;
bottom: 0;
content: '';
position: absolute;
top: 0;
width: 1px;
}
}

.mat-mdc-table-sticky:first-child::before {
right: 0;
}

.mat-mdc-table-sticky:last-child::before {
left: 0;
}
}

.example-sticky-header {
.mat-mdc-header-row th::before {
background-color: #e0e0e0;
bottom: 0;
content: '';
height: 1px;
left: 0;
position: absolute;
right: 0;
}
}

.example-sticky-footer {
td {
background-color: white;
}

.mat-mdc-footer-row td::before {
background-color: #e0e0e0;
content: '';
height: 1px;
left: 0;
position: absolute;
right: 0;
top: 0;
}
}
6 changes: 4 additions & 2 deletions src/dev-app/mdc-table/mdc-table-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const ELEMENT_DATA: PeriodicElement[] = [
styleUrls: ['mdc-table-demo.css'],
})
export class MdcTableDemo {
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
dataSource = ELEMENT_DATA;
readonly displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
readonly displayedColumns2 =
['name', 'position', 'weight', 'symbol', 'position', 'weight', 'symbol', 'star'];
readonly dataSource = ELEMENT_DATA;
}
2 changes: 1 addition & 1 deletion src/material-experimental/mdc-table/table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@include mdc-data-table-core-styles($query: $mat-base-styles-without-animation-query);

.mat-table-sticky {
.mat-mdc-table-sticky {
@include vendor-prefixes.position-sticky;
}

Expand Down