2019-11-15 14:35:25 +08:00
|
|
|
---
|
|
|
|
order: 29
|
|
|
|
title:
|
|
|
|
en-US: Summary
|
|
|
|
zh-CN: 总结栏
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
2020-04-27 15:08:54 +08:00
|
|
|
通过 `summary` 设置总结栏。使用 `Table.Summary.Cell` 同步 Column 的固定状态。
|
2019-11-15 14:35:25 +08:00
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2020-04-27 15:08:54 +08:00
|
|
|
Set summary content by `summary` prop. Sync column fixed status with `Table.Summary.Cell`.
|
2019-11-15 14:35:25 +08:00
|
|
|
|
|
|
|
```jsx
|
|
|
|
import { Table, Typography } from 'antd';
|
|
|
|
|
|
|
|
const { Text } = Typography;
|
|
|
|
|
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
title: 'Name',
|
|
|
|
dataIndex: 'name',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Borrow',
|
|
|
|
dataIndex: 'borrow',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Repayment',
|
|
|
|
dataIndex: 'repayment',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const data = [
|
|
|
|
{
|
|
|
|
key: '1',
|
|
|
|
name: 'John Brown',
|
|
|
|
borrow: 10,
|
|
|
|
repayment: 33,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: '2',
|
|
|
|
name: 'Jim Green',
|
|
|
|
borrow: 100,
|
|
|
|
repayment: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: '3',
|
|
|
|
name: 'Joe Black',
|
|
|
|
borrow: 10,
|
|
|
|
repayment: 10,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: '4',
|
|
|
|
name: 'Jim Red',
|
|
|
|
borrow: 75,
|
|
|
|
repayment: 45,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2020-04-27 15:08:54 +08:00
|
|
|
const fixedColumns = [
|
|
|
|
{
|
|
|
|
title: 'Name',
|
|
|
|
dataIndex: 'name',
|
|
|
|
fixed: true,
|
|
|
|
width: 100,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Description',
|
|
|
|
dataIndex: 'description',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const fixedData = [];
|
|
|
|
for (let i = 0; i < 6; i += 1) {
|
|
|
|
fixedData.push({
|
|
|
|
key: i,
|
|
|
|
name: i % 2 ? 'Light' : 'Bamboo',
|
|
|
|
description: 'Everything that has a beginning, has an end.',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
ReactDOM.render(
|
2020-04-27 15:08:54 +08:00
|
|
|
<>
|
|
|
|
<Table
|
|
|
|
columns={columns}
|
|
|
|
dataSource={data}
|
|
|
|
pagination={false}
|
|
|
|
bordered
|
|
|
|
summary={pageData => {
|
|
|
|
let totalBorrow = 0;
|
|
|
|
let totalRepayment = 0;
|
|
|
|
|
|
|
|
pageData.forEach(({ borrow, repayment }) => {
|
|
|
|
totalBorrow += borrow;
|
|
|
|
totalRepayment += repayment;
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Table.Summary.Row>
|
|
|
|
<Table.Summary.Cell>Total</Table.Summary.Cell>
|
|
|
|
<Table.Summary.Cell>
|
|
|
|
<Text type="danger">{totalBorrow}</Text>
|
|
|
|
</Table.Summary.Cell>
|
|
|
|
<Table.Summary.Cell>
|
|
|
|
<Text>{totalRepayment}</Text>
|
|
|
|
</Table.Summary.Cell>
|
|
|
|
</Table.Summary.Row>
|
|
|
|
<Table.Summary.Row>
|
|
|
|
<Table.Summary.Cell>Balance</Table.Summary.Cell>
|
|
|
|
<Table.Summary.Cell colSpan={2}>
|
|
|
|
<Text type="danger">{totalBorrow - totalRepayment}</Text>
|
|
|
|
</Table.Summary.Cell>
|
|
|
|
</Table.Summary.Row>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
<Table
|
|
|
|
columns={fixedColumns}
|
|
|
|
dataSource={fixedData}
|
|
|
|
pagination={false}
|
|
|
|
scroll={{ x: 2000 }}
|
|
|
|
bordered
|
|
|
|
summary={() => (
|
|
|
|
<Table.Summary.Row>
|
|
|
|
<Table.Summary.Cell index={0}>Summary</Table.Summary.Cell>
|
|
|
|
<Table.Summary.Cell index={1}>This is a summary content</Table.Summary.Cell>
|
|
|
|
</Table.Summary.Row>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</>,
|
2019-11-15 14:35:25 +08:00
|
|
|
mountNode,
|
|
|
|
);
|
|
|
|
```
|
|
|
|
|
|
|
|
<style>
|
|
|
|
#components-table-demo-summary tfoot th,
|
|
|
|
#components-table-demo-summary tfoot td {
|
|
|
|
background: #fafafa;
|
|
|
|
}
|
2019-12-31 10:15:45 +08:00
|
|
|
[data-theme="dark"] #components-table-demo-summary tfoot th,
|
|
|
|
[data-theme="dark"] #components-table-demo-summary tfoot td {
|
2019-12-25 15:14:34 +08:00
|
|
|
background: #1d1d1d;
|
|
|
|
}
|
2019-11-15 14:35:25 +08:00
|
|
|
</style>
|