diff --git a/packages/stark-ui/src/modules/table/components/table.component.spec.ts b/packages/stark-ui/src/modules/table/components/table.component.spec.ts index 2540fa6327..0e0579540e 100644 --- a/packages/stark-ui/src/modules/table/components/table.component.spec.ts +++ b/packages/stark-ui/src/modules/table/components/table.component.spec.ts @@ -209,6 +209,16 @@ describe("TableComponent", () => { expect(component.dataSource.data).toEqual([{ name: "test-data-2" }]); }); + it("should reset 'selection' when 'data' changes", () => { + component.selection.toggle({ name: "selected-data-1" }); + expect(component.selection.selected).toEqual([{ name: "selected-data-1" }]); + + hostComponent.dummyData = [{ name: "data-1" }]; + hostFixture.detectChanges(); + + expect(component.selection.selected).toEqual([]); + }); + it("should assign right value to isFixedHeaderEnabled when fixedHeader changes", () => { hostComponent.fixedHeader = "true"; hostFixture.detectChanges(); diff --git a/packages/stark-ui/src/modules/table/components/table.component.ts b/packages/stark-ui/src/modules/table/components/table.component.ts index b0bf8ab5af..614b7323c0 100644 --- a/packages/stark-ui/src/modules/table/components/table.component.ts +++ b/packages/stark-ui/src/modules/table/components/table.component.ts @@ -484,6 +484,8 @@ export class StarkTableComponent extends AbstractStarkUiComponent implements OnI this.data = this.data || []; if (!changes["data"].isFirstChange()) { + this._resetSelection(); + if (this.resetFilterValueOnDataChange()) { this.filterChanged.emit(this.filter); this.applyFilter();