Skip to content

fix(cdk/table): add fallback code if view repeater isn't provided #20604

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
Sep 23, 2020
Merged
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
45 changes: 31 additions & 14 deletions src/cdk/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,21 +603,38 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
}
const viewContainer = this._rowOutlet.viewContainer;

// @breaking-change 11.0.0 Remove null check for `_viewRepeater`
// once it's a required parameter in the constructor.
this._viewRepeater?.applyChanges(
changes,
viewContainer,
(record: IterableChangeRecord<RenderRow<T>>,
_adjustedPreviousIndex: number|null,
currentIndex: number|null) => this._getEmbeddedViewArgs(record.item, currentIndex!),
(record) => record.item.data,
(change: _ViewRepeaterItemChange<RenderRow<T>, RowContext<T>>) => {
if (change.operation === _ViewRepeaterOperation.INSERTED && change.context) {
this._renderCellTemplateForItem(change.record.item.rowDef, change.context);
// @breaking-change 11.0.0 Remove null check for `_viewRepeater` and the
// `else` clause once `_viewRepeater` is turned into a required parameter.
if (this._viewRepeater) {
this._viewRepeater.applyChanges(
changes,
viewContainer,
(record: IterableChangeRecord<RenderRow<T>>,
_adjustedPreviousIndex: number|null,
currentIndex: number|null) => this._getEmbeddedViewArgs(record.item, currentIndex!),
(record) => record.item.data,
(change: _ViewRepeaterItemChange<RenderRow<T>, RowContext<T>>) => {
if (change.operation === _ViewRepeaterOperation.INSERTED && change.context) {
this._renderCellTemplateForItem(change.record.item.rowDef, change.context);
}
});
} else {
changes.forEachOperation(
(record: IterableChangeRecord<RenderRow<T>>, prevIndex: number|null,
currentIndex: number|null) => {
if (record.previousIndex == null) {
const renderRow = record.item;
const rowDef = renderRow.rowDef;
const context: RowContext<T> = {$implicit: renderRow.data};
this._renderRow(this._rowOutlet, rowDef, currentIndex!, context);
} else if (currentIndex == null) {
viewContainer.remove(prevIndex!);
} else {
const view = <RowViewRef<T>>viewContainer.get(prevIndex!);
viewContainer.move(view!, currentIndex);
}
}
);
});
}

// Update the meta context of a row's context data (index, count, first, last, ...)
this._updateRowIndexContext();
Expand Down