From d20ec1fad2ce28fdf9d1c7e51b9c43c4756600eb Mon Sep 17 00:00:00 2001 From: Sangeetha Babu Date: Wed, 31 Jan 2024 20:33:54 +0530 Subject: [PATCH] fix(datatable): selection function not working as expected (#11449) ### Related Ticket(s) Closes #11349 ### Description To use Selection on DataTable, the documentation states that just need to add the `is-selectable` property in the cds-table tag and setting the prop will automatically set a numerical `selection-name` attribute to every row. This does not happen. ### Changelog **Changed** - Updated the selection functionality to check if `is-selectable` property set to the DataTable, and if so to add `selection-name` property to the rows. --- .../src/components/data-table/table.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/carbon-web-components/src/components/data-table/table.ts b/packages/carbon-web-components/src/components/data-table/table.ts index 9b0bc7ccfea..28a79524488 100644 --- a/packages/carbon-web-components/src/components/data-table/table.ts +++ b/packages/carbon-web-components/src/components/data-table/table.ts @@ -632,6 +632,12 @@ class CDSTable extends HostListenerMixin(LitElement) { } if (changedProperties.has('isSelectable')) { + this._tableHeaderRow.setAttribute('selection-name', 'header'); + this._tableRows.forEach((e, index) => { + if (!e.hasAttribute('selection-name')) { + e.setAttribute('selection-name', index); + } + }); this.headerCount++; }