Skip to content
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
7 changes: 7 additions & 0 deletions src/cdk/table/sticky-styler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ export class StickyStyler {
*/
clearStickyPositioning(rows: HTMLElement[], stickyDirections: StickyDirection[]) {
for (const row of rows) {
// If the row isn't an element (e.g. if it's an `ng-container`),
// it won't have inline styles or `children` so we skip it.
if (row.nodeType !== row.ELEMENT_NODE) {
continue;
}

this._removeStickyStyle(row, stickyDirections);

for (let i = 0; i < row.children.length; i++) {
const cell = row.children[i] as HTMLElement;
this._removeStickyStyle(cell, stickyDirections);
Expand Down
41 changes: 40 additions & 1 deletion src/lib/table/table.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import {DataSource} from '@angular/cdk/collections';
import {Component, OnInit, ViewChild} from '@angular/core';
import {async, ComponentFixture, fakeAsync, flushMicrotasks, TestBed} from '@angular/core/testing';
import {
async,
ComponentFixture,
fakeAsync,
flushMicrotasks,
TestBed,
tick,
} from '@angular/core/testing';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {BehaviorSubject, Observable} from 'rxjs';
import {MatPaginator, MatPaginatorModule} from '../paginator/index';
Expand All @@ -22,6 +29,7 @@ describe('MatTable', () => {
MatTableWithSortApp,
MatTableWithPaginatorApp,
StickyTableApp,
TableWithNgContainerRow,
],
}).compileComponents();
}));
Expand Down Expand Up @@ -127,6 +135,16 @@ describe('MatTable', () => {
expect(stuckCellElement.classList).toContain('mat-table-sticky');
});

// Note: needs to be fakeAsync so it catches the error.
it('should not throw when a row definition is on an ng-container', fakeAsync(() => {
const fixture = TestBed.createComponent(TableWithNgContainerRow);

expect(() => {
fixture.detectChanges();
tick();
}).not.toThrow();
}));

describe('with MatTableDataSource and sort/pagination/filter', () => {
let tableElement: HTMLElement;
let fixture: ComponentFixture<ArrayDataSourceMatTableApp>;
Expand Down Expand Up @@ -750,6 +768,27 @@ class MatTableWithPaginatorApp implements OnInit {
}
}

@Component({
template: `
<mat-table [dataSource]="dataSource">
<ng-container matColumnDef="column_a">
<mat-header-cell *matHeaderCellDef>Column A</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.a}}</mat-cell>
</ng-container>

<mat-header-row *matHeaderRowDef="columnsToRender"></mat-header-row>
<ng-container *matRowDef="let row; columns: columnsToRender">
<mat-row></mat-row>
</ng-container>
</mat-table>
`
})
class TableWithNgContainerRow {
dataSource: FakeDataSource | null = new FakeDataSource();
columnsToRender = ['column_a'];
}


function getElements(element: Element, query: string): Element[] {
return [].slice.call(element.querySelectorAll(query));
}
Expand Down