Commit 21c5299a by chenwq

```

feat(DataTable): 设置操作列默认固定位置并添加表格最小宽度支持

- 将actionColumnFixed属性默认值设置为'right'
- 添加getMinimumTableWidth函数计算表格最小宽度
- 通过scroll.x属性设置表格水平滚动的最小宽度
- 支持嵌套列的宽度计算
```
1 parent 7aee9ab3
...@@ -79,7 +79,7 @@ export function DataTable<T extends object>({ ...@@ -79,7 +79,7 @@ export function DataTable<T extends object>({
rowSelection, rowSelection,
actionColumnTitle = '操作', actionColumnTitle = '操作',
actionColumnWidth, actionColumnWidth,
actionColumnFixed, actionColumnFixed = 'right',
toolbarClassName, toolbarClassName,
toolbarTitle, toolbarTitle,
fillHeight = false, fillHeight = false,
...@@ -196,6 +196,7 @@ export function DataTable<T extends object>({ ...@@ -196,6 +196,7 @@ export function DataTable<T extends object>({
] ]
: [...columns, ...(actionColumn ? [actionColumn] : [])]; : [...columns, ...(actionColumn ? [actionColumn] : [])];
const hasLineLimit = hasLineConfigured(sourceColumns); const hasLineLimit = hasLineConfigured(sourceColumns);
const minTableWidth = getMinimumTableWidth(sourceColumns);
const tableColumns = withLineLimit(sourceColumns); const tableColumns = withLineLimit(sourceColumns);
const TableComponent = fillHeight ? FillTable<T> : UTable<T>; const TableComponent = fillHeight ? FillTable<T> : UTable<T>;
return ( return (
...@@ -226,6 +227,7 @@ export function DataTable<T extends object>({ ...@@ -226,6 +227,7 @@ export function DataTable<T extends object>({
columns={tableColumns} columns={tableColumns}
tableLayout={hasLineLimit ? 'fixed' : undefined} tableLayout={hasLineLimit ? 'fixed' : undefined}
rowSelection={resolvedSelection} rowSelection={resolvedSelection}
scroll={{ ...props.scroll, x: props.scroll?.x ?? minTableWidth }}
styles={{ styles={{
header: { cell: { paddingLeft: 20 } }, header: { cell: { paddingLeft: 20 } },
body: { cell: { paddingLeft: 20 } }, body: { cell: { paddingLeft: 20 } },
...@@ -266,6 +268,15 @@ function hasLineConfigured<T extends object>(columns: ColumnsType<T>): boolean { ...@@ -266,6 +268,15 @@ function hasLineConfigured<T extends object>(columns: ColumnsType<T>): boolean {
}); });
} }
function getMinimumTableWidth<T extends object>(columns: ColumnsType<T>): number {
return columns.reduce((width, column) => {
if ('children' in column && column.children) {
return width + getMinimumTableWidth(column.children);
}
return width + (typeof column.width === 'number' ? column.width : 120);
}, 0);
}
function withLineLimit<T extends object>(columns: DataTableColumnsType<T>): ColumnsType<T> { function withLineLimit<T extends object>(columns: DataTableColumnsType<T>): ColumnsType<T> {
return columns.map((column) => { return columns.map((column) => {
if ('children' in column && column.children) { if ('children' in column && column.children) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!