Skip to content

Commit

Permalink
fix(platform): reset table rows before new rows emitted
Browse files Browse the repository at this point in the history
  • Loading branch information
N1XUS committed Dec 7, 2023
1 parent fe6ea50 commit 34ba545
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,6 @@ export class TableDataSourceDirective<T> extends DataSourceDirective<T, TableDat

this._tableDsSubscription?.unsubscribe();
this._tableDsSubscription = null;
this._table.clearTableRows();
}
}
2 changes: 2 additions & 0 deletions libs/platform/src/lib/table-helpers/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ export abstract class Table<T = any> implements PresetManagedComponent<PlatformT

abstract refreshDndList(): void;

abstract clearTableRows(): void;

/** Toolbar Sort Settings button click event */
readonly openTableSortSettings: EventEmitter<void> = new EventEmitter<void>();

Expand Down
20 changes: 11 additions & 9 deletions libs/platform/src/lib/table/table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,17 @@ export class TableComponent<T = any>
tableEl.rows[position.rowIndex].cells[position.colIndex].focus();
}

/**
* Clears the array of table rows. Triggered when new data source is applied.
*/
clearTableRows(): void {
this._tableRows = [];
this._tableRowsVisible = [];
this._tableRowsInViewPortPlaceholder = [];
this._newTableRows = [];
this._dataSourceTableRows = [];
}

// Private API

/** @hidden */
Expand Down Expand Up @@ -1544,15 +1555,6 @@ export class TableComponent<T = any>

/** @hidden */
private _listenToTableRowsPipe(): void {
this._subscriptions.add(
/*
* Reset table when the data source is changed,
* because new data source can have different set of data
*/
this._dataSourceDirective.dataSourceChanged.subscribe(() => {
this._setTableRows([]);
})
);
this._subscriptions.add(
this._dataSourceDirective.items$
.pipe(
Expand Down

0 comments on commit 34ba545

Please sign in to comment.