* Renders rows based on the table's latest set of data, which was either provided directly as an * input or retrieved through an Observable stream (directly or from a DataSource). * Checks for differences in the data since the last diff to perform only the necessary * changes (add/remove/mo
()
| 735 | * an array, this function will need to be called to render any changes. |
| 736 | */ |
| 737 | renderRows() { |
| 738 | this._renderRows = this._getAllRenderRows(); |
| 739 | const changes = this._dataDiffer.diff(this._renderRows); |
| 740 | if (!changes) { |
| 741 | this._updateNoDataRow(); |
| 742 | this.contentChanged.next(); |
| 743 | return; |
| 744 | } |
| 745 | const viewContainer = this._rowOutlet.viewContainer; |
| 746 | |
| 747 | this._viewRepeater.applyChanges( |
| 748 | changes, |
| 749 | viewContainer, |
| 750 | ( |
| 751 | record: IterableChangeRecord<RenderRow<T>>, |
| 752 | _adjustedPreviousIndex: number | null, |
| 753 | currentIndex: number | null, |
| 754 | ) => this._getEmbeddedViewArgs(record.item, currentIndex!), |
| 755 | record => record.item.data, |
| 756 | (change: _ViewRepeaterItemChange<RenderRow<T>, RowContext<T>>) => { |
| 757 | if (change.operation === _ViewRepeaterOperation.INSERTED && change.context) { |
| 758 | this._renderCellTemplateForItem(change.record.item.rowDef, change.context); |
| 759 | const rowView = viewContainer.get(change.record.currentIndex!) as RowViewRef<T>; |
| 760 | this._rowDefsByView.set(rowView, change.record.item.rowDef); |
| 761 | } |
| 762 | }, |
| 763 | ); |
| 764 | |
| 765 | // Update rows that did not get added/removed/moved but may have had their identity changed, |
| 766 | // e.g. if trackBy matched data on some property but the actual data reference changed. |
| 767 | changes.forEachIdentityChange((record: IterableChangeRecord<RenderRow<T>>) => { |
| 768 | const currentIndex = record.currentIndex!; |
| 769 | const rowView = viewContainer.get(currentIndex) as RowViewRef<T>; |
| 770 | |
| 771 | if (this._rowDefsByView.get(rowView) !== record.item.rowDef) { |
| 772 | viewContainer.remove(currentIndex); |
| 773 | const newRowView = this._renderRow(this._rowOutlet, record.item.rowDef, currentIndex, { |
| 774 | $implicit: record.item.data, |
| 775 | }); |
| 776 | this._rowDefsByView.set(newRowView, record.item.rowDef); |
| 777 | } else { |
| 778 | rowView.context.$implicit = record.item.data; |
| 779 | } |
| 780 | }); |
| 781 | |
| 782 | // Update the meta context of a row's context data (index, count, first, last, ...) |
| 783 | this._updateRowIndexContext(); |
| 784 | |
| 785 | this._updateNoDataRow(); |
| 786 | |
| 787 | this.contentChanged.next(); |
| 788 | this.updateStickyColumnStyles(); |
| 789 | } |
| 790 | |
| 791 | /** Adds a column definition that was not included as part of the content children. */ |
| 792 | addColumnDef(columnDef: CdkColumnDef) { |
no test coverage detected