From a501c29be5cbd2255a69f1877bc24e01d0bbc9a1 Mon Sep 17 00:00:00 2001 From: jiazan-wen Date: Mon, 14 Feb 2022 19:04:51 +0800 Subject: [PATCH] fix(data-table): fix cannot click selection checkbox --- CHANGELOG.en-US.md | 1 + CHANGELOG.zh-CN.md | 1 + src/data-table/src/use-table-data.ts | 20 +++++++++++++------- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index f93f2887f8b..b3c0fcd836f 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -6,6 +6,7 @@ - Fix `n-switch` can't use keyboard operation when checked value is customized. - Fix `n-data-table`'s fixed column is covered by scroll content when placed inside popover. +- Fix `n-data-table` cannot click selection checkbox if the selection column is a column's child. ### Feats diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index 43973ff1f11..d1ceecd4249 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -6,6 +6,7 @@ - 修复 `n-switch` 在自定义选中值的时候无法使用键盘操作 - 修复 `n-data-table` 放在 popover 内使用固定列滚动内容覆盖 +- 修复 `n-data-table` 当 selection column 为某个 column 的子 column 时无法点击全选复选框 ### Feats diff --git a/src/data-table/src/use-table-data.ts b/src/data-table/src/use-table-data.ts index 85c015ee226..93b73530583 100644 --- a/src/data-table/src/use-table-data.ts +++ b/src/data-table/src/use-table-data.ts @@ -32,14 +32,20 @@ export function useTableData ( } ) { const selectionColumnRef = computed(() => { - return ( - (props.columns.find((col) => { - if (col.type === 'selection') { - return true + const getSelectionColumn = ( + cols: typeof props.columns + ): TableSelectionColumn | null => { + for (let i = 0; i < cols.length; ++i) { + const col = cols[i] + if ('children' in col) { + return getSelectionColumn(col.children) + } else if (col.type === 'selection') { + return col } - return false - }) as TableSelectionColumn | undefined) || null - ) + } + return null + } + return getSelectionColumn(props.columns) }) const treeMateRef = computed(() => {