Skip to content

fix(table): 修复树形模式关联选择时,全选与行选择返回的已选数据结构不一致的问题 #5468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/components/table/hooks/useTreeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,12 @@ export default function useTreeSelect(props: TdEnhancedTableProps, treeDataMap:
}

function onInnerSelectChange(rowKeys: SelectChangeParams[0], extraData: SelectChangeParams[1]) {
// 非关联选择无论单选多选直接返回,数据格式与非树形table一致
if (!tree.value || tree.value.checkStrictly) {
setTSelectedRowKeys(rowKeys, extraData);
return;
}
// 关联选择,行选择和全选,均使用getRowDataByKeys获取带tree元数据的结构返回
if (extraData.currentRowKey === 'CHECK_ALL_BOX') {
handleSelectAll(extraData);
} else {
Expand All @@ -194,20 +196,20 @@ export default function useTreeSelect(props: TdEnhancedTableProps, treeDataMap:

function handleSelectAll(extraData: SelectChangeParams[1]) {
const newRowKeys: Array<string | number> = [];
const newRowData: TableRowData[] = [];
if (extraData.type === 'check') {
const arr = [...treeDataMap.value.values()];
for (let i = 0, len = arr.length; i < len; i++) {
const item = arr[i];
if (!item.disabled) {
newRowData.push(item.row);
newRowKeys.push(get(item.row, rowDataKeys.value.rowKey));
}
}
}
// 这里用getRowDataByKeys返回带row的节点对象(全选)
const newRowData = getRowDataByKeys({ treeDataMap: treeDataMap.value, selectedRowKeys: newRowKeys });
const newExtraData = {
...extraData,
selectedRowData: newRowData || [],
selectedRowData: newRowData,
};
setTSelectedRowKeys(newRowKeys, newExtraData);
}
Expand All @@ -230,6 +232,7 @@ export default function useTreeSelect(props: TdEnhancedTableProps, treeDataMap:
}
}
newRowKeys = updateParentCheckedState(newRowKeys, extraData.currentRowKey, extraData.type);
// 这里用getRowDataByKeys返回带row的节点对象(行选择)
const newRowData = getRowDataByKeys({ treeDataMap: treeDataMap.value, selectedRowKeys: newRowKeys });
const newExtraData = {
...extraData,
Expand Down