2019-11-15 14:35:25 +08:00
---
order: 29
title:
en-US: Summary
zh-CN: 总结栏
---
## zh-CN
2021-05-25 16:12:41 +08:00
通过 `summary` 设置总结栏。使用 `Table.Summary.Cell` 同步 Column 的固定状态。你可以通过配置 `Table.Summary` 的 `fixed` 属性使其固定(`4.16.0` 支持)。
2019-11-15 14:35:25 +08:00
## en-US
2021-05-25 16:12:41 +08:00
Set summary content by `summary` prop. Sync column fixed status with `Table.Summary.Cell` . You can fixed it by set `Table.Summary` `fixed` prop(since `4.16.0` ).
2019-11-15 14:35:25 +08:00
2022-05-19 09:46:26 +08:00
```tsx
2019-11-15 14:35:25 +08:00
import { Table, Typography } from 'antd';
2022-05-19 09:46:26 +08:00
import type { ColumnsType } from 'antd/lib/table';
2022-05-23 14:37:16 +08:00
import React from 'react';
2019-11-15 14:35:25 +08:00
const { Text } = Typography;
2022-05-19 09:46:26 +08:00
interface DataType {
key: string;
name: string;
borrow: number;
repayment: number;
}
interface FixedDataType {
key: React.Key;
name: string;
description: string;
}
const columns: ColumnsType< DataType > = [
2019-11-15 14:35:25 +08:00
{
title: 'Name',
dataIndex: 'name',
},
{
title: 'Borrow',
dataIndex: 'borrow',
},
{
title: 'Repayment',
dataIndex: 'repayment',
},
];
2022-05-19 09:46:26 +08:00
const data: DataType[] = [
2019-11-15 14:35:25 +08:00
{
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,
},
];
2022-05-19 09:46:26 +08:00
const fixedColumns: ColumnsType< FixedDataType > = [
2020-04-27 15:08:54 +08:00
{
title: 'Name',
dataIndex: 'name',
fixed: true,
width: 100,
},
{
title: 'Description',
dataIndex: 'description',
},
];
2022-05-19 09:46:26 +08:00
const fixedData: FixedDataType[] = [];
2021-05-25 16:12:41 +08:00
for (let i = 0; i < 20 ; i + = 1 ) {
2020-04-27 15:08:54 +08:00
fixedData.push({
key: i,
2021-05-25 16:12:41 +08:00
name: ['Light', 'Bamboo', 'Little'][i % 3],
2020-04-27 15:08:54 +08:00
description: 'Everything that has a beginning, has an end.',
});
}
2022-05-19 09:46:26 +08:00
const App: React.FC = () => (
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 >
2022-05-19 09:46:26 +08:00
< Table.Summary.Cell index = {0} > Total< / Table.Summary.Cell >
< Table.Summary.Cell index = {1} >
2020-04-27 15:08:54 +08:00
< Text type = "danger" > {totalBorrow}< / Text >
< / Table.Summary.Cell >
2022-05-19 09:46:26 +08:00
< Table.Summary.Cell index = {2} >
2020-04-27 15:08:54 +08:00
< Text > {totalRepayment}< / Text >
< / Table.Summary.Cell >
< / Table.Summary.Row >
< Table.Summary.Row >
2022-05-19 09:46:26 +08:00
< Table.Summary.Cell index = {0} > Balance< / Table.Summary.Cell >
< Table.Summary.Cell index = {1} colSpan = {2} >
2020-04-27 15:08:54 +08:00
< Text type = "danger" > {totalBorrow - totalRepayment}< / Text >
< / Table.Summary.Cell >
< / Table.Summary.Row >
< />
);
}}
/>
< br / >
< Table
columns={fixedColumns}
dataSource={fixedData}
pagination={false}
2021-05-25 16:12:41 +08:00
scroll={{ x: 2000, y: 500 }}
2020-04-27 15:08:54 +08:00
bordered
summary={() => (
2021-05-25 16:12:41 +08:00
< Table.Summary fixed >
< 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 >
< / Table.Summary >
2020-04-27 15:08:54 +08:00
)}
/>
2022-04-03 23:27:45 +08:00
< />
2019-11-15 14:35:25 +08:00
);
2022-05-19 09:46:26 +08:00
export default App;
2019-11-15 14:35:25 +08:00
```
< 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 >