This repository has been archived by the owner on Mar 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💄 UI: optimize the style of nested tables (#617)
* 💄 UI: optimize the style of nested tables * use father
- Loading branch information
1 parent
9ce13fc
commit 11c3709
Showing
7 changed files
with
154 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,7 @@ nav: | |
## 轮询 | ||
|
||
<code src="./example/pollinga.tsx" /> | ||
|
||
## 嵌套表格 | ||
|
||
<code src="./example/nested-table.tsx" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import ProTable, { ProColumns } from '@ant-design/pro-table'; | ||
|
||
const valueEnum = { | ||
0: 'close', | ||
1: 'running', | ||
2: 'online', | ||
3: 'error', | ||
}; | ||
|
||
export interface TableListItem { | ||
key: number; | ||
name: string; | ||
status: string; | ||
updatedAt: number; | ||
createdAt: number; | ||
progress: number; | ||
money: number; | ||
} | ||
const tableListDataSource: TableListItem[] = []; | ||
|
||
for (let i = 0; i < 1; i += 1) { | ||
tableListDataSource.push({ | ||
key: i, | ||
name: `TradeCode ${i}`, | ||
status: valueEnum[Math.floor(Math.random() * 10) % 4], | ||
updatedAt: Date.now() - Math.floor(Math.random() * 1000), | ||
createdAt: Date.now() - Math.floor(Math.random() * 2000), | ||
money: Math.floor(Math.random() * 2000) * i, | ||
progress: Math.ceil(Math.random() * 100) + 1, | ||
}); | ||
} | ||
|
||
const columns: ProColumns<TableListItem>[] = [ | ||
{ | ||
title: '序号', | ||
dataIndex: 'index', | ||
valueType: 'index', | ||
width: 80, | ||
}, | ||
{ | ||
title: '状态', | ||
dataIndex: 'status', | ||
initialValue: 'all', | ||
width: 100, | ||
filters: true, | ||
valueEnum: { | ||
all: { text: '全部', status: 'Default' }, | ||
close: { text: '关闭', status: 'Default' }, | ||
running: { text: '运行中', status: 'Processing' }, | ||
online: { text: '已上线', status: 'Success' }, | ||
error: { text: '异常', status: 'Error' }, | ||
}, | ||
}, | ||
{ | ||
title: '进度', | ||
key: 'progress', | ||
dataIndex: 'progress', | ||
valueType: (item) => ({ | ||
type: 'progress', | ||
status: item.status !== 'error' ? 'active' : 'exception', | ||
}), | ||
width: 200, | ||
}, | ||
{ | ||
title: '更新时间', | ||
key: 'since2', | ||
width: 120, | ||
dataIndex: 'createdAt', | ||
valueType: 'date', | ||
}, | ||
]; | ||
|
||
const expandedRowRender = () => { | ||
const data = []; | ||
for (let i = 0; i < 3; i += 1) { | ||
data.push({ | ||
key: i, | ||
date: '2014-12-24 23:12:00', | ||
name: 'This is production name', | ||
upgradeNum: 'Upgraded: 56', | ||
}); | ||
} | ||
return ( | ||
<ProTable | ||
columns={[ | ||
{ title: 'Date', dataIndex: 'date', key: 'date' }, | ||
{ title: 'Name', dataIndex: 'name', key: 'name' }, | ||
{ | ||
title: 'Status', | ||
key: 'state', | ||
}, | ||
{ title: 'Upgrade Status', dataIndex: 'upgradeNum', key: 'upgradeNum' }, | ||
{ | ||
title: 'Action', | ||
dataIndex: 'operation', | ||
key: 'operation', | ||
render: () => [<a>Pause</a>, <a>Stop</a>], | ||
}, | ||
]} | ||
headerTitle={false} | ||
search={false} | ||
options={false} | ||
dataSource={data} | ||
pagination={false} | ||
/> | ||
); | ||
}; | ||
|
||
export default () => { | ||
const [dataSource, setDataSource] = useState<TableListItem[]>([]); | ||
useEffect(() => { | ||
setDataSource(tableListDataSource); | ||
}, []); | ||
return ( | ||
<ProTable<TableListItem> | ||
columns={columns} | ||
rowKey="key" | ||
pagination={{ | ||
showSizeChanger: true, | ||
}} | ||
dataSource={dataSource} | ||
expandable={{ expandedRowRender }} | ||
dateFormatter="string" | ||
headerTitle="嵌套表格" | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters