Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-platform
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈智峰
jinfa-platform
Commits
c5ac6107
Commit
c5ac6107
authored
Sep 24, 2020
by
GuanHua
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
http://10.0.0.22:3000/lingxi/lingxi-business-paltform
into dev
parents
804c371b
1a3a0dea
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
0 deletions
+56
-0
index.less
src/components/NestTable/index.less
+0
-0
index.tsx
src/components/NestTable/index.tsx
+56
-0
No files found.
src/components/NestTable/index.less
0 → 100644
View file @
c5ac6107
src/components/NestTable/index.tsx
0 → 100644
View file @
c5ac6107
import
React
,
{
useCallback
}
from
'react'
import
{
Table
}
from
'antd'
import
{
TableProps
,
ColumnsType
}
from
'antd/es/table'
import
{
CaretRightOutlined
,
CaretDownOutlined
}
from
'@ant-design/icons'
export
interface
NestTableProps
extends
TableProps
<
any
>
{
/**
* 扁平化的递归嵌套类型, 后面一项永远为前一项的直系子集
*/
NestColumns
:
ColumnsType
<
any
>
[],
// 指定获得的子集数据类型
childrenDataKey
:
string
}
/**
* 嵌套表格
* @todo 实现无限嵌套, 目前暂时实现两层
*/
const
NestTable
:
React
.
FC
<
NestTableProps
>
=
(
props
)
=>
{
const
{
NestColumns
,
childrenDataKey
,
dataSource
,
...
resetProps
}
=
props
if
(
NestColumns
.
length
>
2
)
{
throw
new
Error
(
'暂时不支持2项以上的嵌套table'
)
}
const
[
parentColumns
=
[],
childColumns
=
[]]
=
NestColumns
const
childRenderTable
=
useCallback
((
record
)
=>
{
return
<
Table
columns=
{
childColumns
}
dataSource=
{
dataSource
[
childrenDataKey
]
||
[]
}
/>
},
[
childColumns
,
dataSource
])
return
(
<
Table
columns=
{
parentColumns
}
dataSource=
{
dataSource
}
expandable=
{
{
expandedRowRender
:
childRenderTable
,
expandIcon
:
({
expanded
,
onExpand
,
record
})
=>
expanded
?
(
<
CaretRightOutlined
onClick=
{
e
=>
onExpand
(
record
,
e
)
}
/>
)
:
(
<
CaretDownOutlined
onClick=
{
e
=>
onExpand
(
record
,
e
)
}
/>
)
}
}
pagination=
{
false
}
{
...
resetProps
}
/>
)
}
NestTable
.
defaultProps
=
{}
export
default
NestTable
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment