From c0d2f34f309bce735476cffe7f5c2f7ada936603 Mon Sep 17 00:00:00 2001 From: Alexis Georges <alexis@georges.brussels> Date: Tue, 30 Jul 2019 11:49:32 +0200 Subject: [PATCH] fix(stark-ui): table - when data changes, selection is now reset ISSUES CLOSED: #1366 --- .../modules/table/components/table.component.spec.ts | 10 ++++++++++ .../src/modules/table/components/table.component.ts | 2 ++ 2 files changed, 12 insertions(+) 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();