feat: add expand all rows

This commit is contained in:
jialin
2025-03-05 14:05:12 +08:00
parent 3fdde5f8c4
commit fd7ce9027a
12 changed files with 92 additions and 33 deletions
+13
View File
@@ -16,6 +16,7 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
rowKey,
childParentKey,
onExpand,
onExpandAll,
onSort,
onCell,
expandedRowKeys,
@@ -51,6 +52,12 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
});
}, [columns, children]);
const expandAll = useMemo(() => {
const allKeys = new Set(expandedRowKeys);
const currentDataKeys = props.dataSource.map((record) => record[rowKey]);
return currentDataKeys.every((key) => allKeys.has(key));
}, [props.dataSource, expandedRowKeys]);
const selectState = useMemo(() => {
const selectedRowKeys = rowSelection?.selectedRowKeys || [];
const selectedKeys = new Set(selectedRowKeys);
@@ -99,6 +106,10 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
}
};
const handleExpandAll = (value: boolean) => {
onExpandAll?.(value);
};
const handlePageChange = (page: number, pageSize: number) => {
pagination?.onChange?.(page, pageSize);
};
@@ -115,6 +126,8 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
selectAll={selectState.selectAll}
indeterminate={selectState.indeterminate}
onSelectAll={handleSelectAllChange}
onExpandAll={handleExpandAll}
expandAll={expandAll}
expandable={expandable}
enableSelection={rowSelection?.enableSelection}
hasColumns={parsedColumns.length > 0}