From a1e0313d49d2a5988c8d67da10af56ebc8c47b9b Mon Sep 17 00:00:00 2001 From: Sangeetha Babu <58620134+sangeethababu9223@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:26:07 +0530 Subject: [PATCH] fix(datatable): is sortable not working in table header cell --- .../data-table/table-header-cell.ts | 4 ++-- .../src/components/data-table/table.ts | 21 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/carbon-web-components/src/components/data-table/table-header-cell.ts b/packages/carbon-web-components/src/components/data-table/table-header-cell.ts index 119b639fa3d..850213344e5 100644 --- a/packages/carbon-web-components/src/components/data-table/table-header-cell.ts +++ b/packages/carbon-web-components/src/components/data-table/table-header-cell.ts @@ -130,13 +130,13 @@ class CDSTableHeaderCell extends FocusMixin(LitElement) { /** * `true` if the table has expandable rows */ - @property({ type: Boolean, reflect: true, attribute: 'is-sortable' }) + @property({ type: Boolean, reflect: true, attribute: 'expandable' }) isExpandable = false; /** * `true` if this table has selectable rows */ - @property({ type: Boolean, reflect: true, attribute: 'is-sortable' }) + @property({ type: Boolean, reflect: true, attribute: 'is-selectable' }) isSelectable = false; /** * `true` if this table header column should be sortable 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 4bee2b8f1ec..a4858bbabef 100644 --- a/packages/carbon-web-components/src/components/data-table/table.ts +++ b/packages/carbon-web-components/src/components/data-table/table.ts @@ -404,9 +404,13 @@ class CDSTable extends HostListenerMixin(LitElement) { const columns = [...this._tableHeaderRow.children]; const columnIndex = columns.indexOf(target); - columns.forEach( - (e) => e !== target && e.setAttribute('sort-direction', 'none') - ); + columns.forEach((e) => { + if (e !== target && this.isSortable) { + e.setAttribute('sort-direction', 'none'); + } else if (e.hasAttribute('is-sortable')) { + e.setAttribute('sort-direction', 'none'); + } + }); this._handleSortAction(columnIndex, sortDirection); @@ -821,10 +825,13 @@ class CDSTable extends HostListenerMixin(LitElement) { } }); - columns.forEach( - (e, index) => - index !== columnIndex && e.setAttribute('sort-direction', 'none') - ); + columns.forEach((e, index) => { + if (index !== columnIndex && this.isSortable) { + e.setAttribute('sort-direction', 'none'); + } else if (e.hasAttribute('is-sortable')) { + e.setAttribute('sort-direction', 'none'); + } + }); this._handleSortAction(columnIndex, sortDirection); }