Skip to content
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

fix(table): enhanced tree table can not expand with expected #2661

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/table/_example/tree-select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ export default function TableSingleSort() {
});
};

// 树节点展开,受控示例
// const [expandedTreeNodes, setExpandedTreeNodes] = useState(['first_level_0']);

return (
<Space direction="vertical">
<Space>
Expand Down Expand Up @@ -174,6 +177,8 @@ export default function TableSingleSort() {
onExpandChange={onExpandChange}
onRowClick={onRowClick}
lazyLoad
// expandedTreeNodes={expandedTreeNodes}
// onExpandedTreeNodesChange={setExpandedTreeNodes}
/>
</Space>
);
Expand Down
2 changes: 1 addition & 1 deletion src/table/hooks/useTreeData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default function useTreeData(props: TdEnhancedTableProps) {
const defaultNeedExpand = Boolean(!isDefaultExpandedTreeNodesExecute && defaultExpandedTreeNodes?.length);
const needExpandAll = Boolean(tree?.defaultExpandAll && !isDefaultExpandAllExecute);
if ((tExpandedTreeNode?.length && !!(expandedTreeNodes || defaultNeedExpand)) || needExpandAll) {
updateExpandOnDataChange(data);
updateExpandOnDataChange([...data]);
setIsDefaultExpandedTreeNodesExecute(true);
} else {
setDataSource([...data]);
Expand Down
4 changes: 2 additions & 2 deletions src/table/hooks/useTreeDataExpand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function useTreeDataExpand(
const newData = store.toggleExpandData({ row, rowIndex }, dataSource, rowDataKeys);
setDataSource([...newData]);
} else if (changedExpandTreeNode.type === 'props-change') {
updateExpandState(dataSource, tExpandedTreeNode, oldExpandedTreeNode);
updateExpandState([...dataSource], tExpandedTreeNode, oldExpandedTreeNode);
}
if (changedExpandTreeNode.type !== 'props-change') {
setChangedExpandTreeNode({ type: 'props-change' });
Expand All @@ -136,7 +136,7 @@ export function useTreeDataExpand(
} else if (tExpandedTreeNode?.length) {
setTimeout(() => {
const newData = updateExpandState([...data], tExpandedTreeNode, []);
setDataSource(newData);
setDataSource([...newData]);
});
}
};
Expand Down
Loading