From 7ff7b505180bf61f48868ae3da083d0c53d945ee Mon Sep 17 00:00:00 2001 From: Benjamin <166110368+BenjaminPabst@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:15:02 +0200 Subject: [PATCH] feat: allow disable of row selection (#406) feat: allow disable of row selection --- .../data-table/data-table.component.html | 5 +++- .../data-table/data-table.component.spec.ts | 25 +++++++++++++++++++ .../data-table/data-table.component.ts | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/libs/angular-accelerator/src/lib/components/data-table/data-table.component.html b/libs/angular-accelerator/src/lib/components/data-table/data-table.component.html index 29735f6b..f39cae63 100644 --- a/libs/angular-accelerator/src/lib/components/data-table/data-table.component.html +++ b/libs/angular-accelerator/src/lib/components/data-table/data-table.component.html @@ -188,7 +188,10 @@ - + diff --git a/libs/angular-accelerator/src/lib/components/data-table/data-table.component.spec.ts b/libs/angular-accelerator/src/lib/components/data-table/data-table.component.spec.ts index 88fc8b7d..e1808e7f 100644 --- a/libs/angular-accelerator/src/lib/components/data-table/data-table.component.spec.ts +++ b/libs/angular-accelerator/src/lib/components/data-table/data-table.component.spec.ts @@ -367,6 +367,31 @@ describe('DataTableComponent', () => { expect(selectedCheckBoxes.length).toBe(1) expect(selectionChangedEvent).toEqual([mockData[0]]) }) + + it('should not change selection if selection disabled', async () => { + let selectionChangedEvent: Row[] | undefined + + component.selectionEnabledField = 'selectionEnabled' + + component.rows = mockData.map((m) => ({ + ...m, + selectionEnabled: false, + })) + + component.selectionChanged.subscribe((event) => (selectionChangedEvent = event)) + unselectedCheckBoxes = await dataTable.getHarnessesForCheckboxes('unchecked') + selectedCheckBoxes = await dataTable.getHarnessesForCheckboxes('checked') + expect(unselectedCheckBoxes.length).toBe(5) + expect(selectedCheckBoxes.length).toBe(0) + expect(selectionChangedEvent).toBeUndefined() + + const firstRowCheckBox = unselectedCheckBoxes[0] + await firstRowCheckBox.checkBox() + unselectedCheckBoxes = await dataTable.getHarnessesForCheckboxes('unchecked') + selectedCheckBoxes = await dataTable.getHarnessesForCheckboxes('checked') + expect(unselectedCheckBoxes.length).toBe(5) + expect(selectedCheckBoxes.length).toBe(0) + }) }) describe('Frozen action column', () => { diff --git a/libs/angular-accelerator/src/lib/components/data-table/data-table.component.ts b/libs/angular-accelerator/src/lib/components/data-table/data-table.component.ts index b0472e0b..165aff96 100644 --- a/libs/angular-accelerator/src/lib/components/data-table/data-table.component.ts +++ b/libs/angular-accelerator/src/lib/components/data-table/data-table.component.ts @@ -116,6 +116,7 @@ export class DataTableComponent extends DataSortBase implements OnInit { @Input() viewActionEnabledField: string | undefined @Input() editActionVisibleField: string | undefined @Input() editActionEnabledField: string | undefined + @Input() selectionEnabledField: string | undefined @Input() paginator = true @Input() page = 0 @Input()