From fb7443f5d73629202cd2520fcf2d38cab7241872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Mon, 1 Jul 2024 09:56:14 +0300 Subject: [PATCH 1/2] Fixed #15903 - Table | Multiple Selection with dataKey shows wrong selected row count upon CTRL+A --- src/app/components/table/table.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/components/table/table.ts b/src/app/components/table/table.ts index aa4873daa12..41caa9dcf73 100644 --- a/src/app/components/table/table.ts +++ b/src/app/components/table/table.ts @@ -1849,7 +1849,7 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable } } - selectRange(event: MouseEvent | KeyboardEvent, rowIndex: number) { + selectRange(event: MouseEvent | KeyboardEvent, rowIndex: number, isCtrlASelection? : boolean | undefined) { let rangeStart, rangeEnd; if (this.anchorRowIndex > rowIndex) { @@ -1871,13 +1871,15 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable let rangeRowsData = []; for (let i = rangeStart; i <= rangeEnd; i++) { let rangeRowData = this.filteredValue ? this.filteredValue[i] : this.value[i]; - if (!this.isSelected(rangeRowData)) { + if (!this.isSelected(rangeRowData) && !isCtrlASelection) { if (!this.isRowSelectable(rangeRowData, rowIndex)) { continue; } rangeRowsData.push(rangeRowData); + this._selection = [...this.selection, rangeRowData]; + let dataKeyValue = this.dataKey ? String(ObjectUtils.resolveFieldData(rangeRowData, this.dataKey)) : null; if (dataKeyValue) { this.selectionKeys[dataKeyValue] = 1; @@ -3632,7 +3634,7 @@ export class SelectableRow implements OnInit, OnDestroy { if (event.code === 'KeyA' && (event.metaKey || event.ctrlKey) && this.dt.selectionMode === 'multiple') { const data = this.dt.dataToRender(this.dt.processedData); this.dt.selection = [...data]; - this.dt.selectRange(event, data.length - 1); + this.dt.selectRange(event, data.length - 1, true); event.preventDefault(); } From 10281dc692037884059a04ccb0997315b1ccc68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Thu, 4 Jul 2024 11:58:54 +0300 Subject: [PATCH 2/2] refactor --- src/app/components/table/table.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/components/table/table.ts b/src/app/components/table/table.ts index bfa640a8414..5c28388c42f 100644 --- a/src/app/components/table/table.ts +++ b/src/app/components/table/table.ts @@ -1849,7 +1849,7 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable } } - selectRange(event: MouseEvent | KeyboardEvent, rowIndex: number, isCtrlASelection? : boolean | undefined) { + selectRange(event: MouseEvent | KeyboardEvent, rowIndex: number, isMetaKeySelection? : boolean | undefined) { let rangeStart, rangeEnd; if (this.anchorRowIndex > rowIndex) { @@ -1871,7 +1871,7 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable let rangeRowsData = []; for (let i = rangeStart; i <= rangeEnd; i++) { let rangeRowData = this.filteredValue ? this.filteredValue[i] : this.value[i]; - if (!this.isSelected(rangeRowData) && !isCtrlASelection) { + if (!this.isSelected(rangeRowData) && !isMetaKeySelection) { if (!this.isRowSelectable(rangeRowData, rowIndex)) { continue; }