Commit a26d6757 authored by XieZhiXiong's avatar XieZhiXiong

feat: columns 支持函数类型

parent d1076053
...@@ -6,8 +6,9 @@ import { CaretRightOutlined, CaretDownOutlined } from '@ant-design/icons' ...@@ -6,8 +6,9 @@ import { CaretRightOutlined, CaretDownOutlined } from '@ant-design/icons'
export interface NestTableProps extends TableProps<any> { export interface NestTableProps extends TableProps<any> {
/** /**
* 扁平化的递归嵌套类型, 后面一项永远为前一项的直系子集 * 扁平化的递归嵌套类型, 后面一项永远为前一项的直系子集
* column 可以是函数,此时可以根据业务返回不同的 column
*/ */
NestColumns: ColumnsType<any>[], NestColumns: (ColumnsType<any> | ((record?) => ColumnsType<any>))[],
// 指定获得的子集数据类型 // 指定获得的子集数据类型
childrenDataKey: string, childrenDataKey: string,
childPagination?: false | TablePaginationConfig, childPagination?: false | TablePaginationConfig,
...@@ -28,7 +29,7 @@ const NestTable: React.FC<NestTableProps> = (props) => { ...@@ -28,7 +29,7 @@ const NestTable: React.FC<NestTableProps> = (props) => {
const childRenderTable = useCallback((record) => { const childRenderTable = useCallback((record) => {
return <Table return <Table
columns={childColumns} columns={typeof childColumns !== 'function' ? childColumns : childColumns(record)}
size="middle" size="middle"
dataSource={record[childrenDataKey] || []} dataSource={record[childrenDataKey] || []}
rowClassName={(_, index) => (index % 2) === 0 && "tb_bg"} rowClassName={(_, index) => (index % 2) === 0 && "tb_bg"}
...@@ -40,7 +41,7 @@ const NestTable: React.FC<NestTableProps> = (props) => { ...@@ -40,7 +41,7 @@ const NestTable: React.FC<NestTableProps> = (props) => {
return ( return (
<Table <Table
columns={parentColumns} columns={parentColumns as ColumnsType<any>}
dataSource={dataSource} dataSource={dataSource}
expandable={{ expandable={{
expandedRowRender: childRenderTable, expandedRowRender: childRenderTable,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment