gpt4 book ai didi

reactjs - antd 表总结

转载 作者:行者123 更新时间:2023-12-03 13:50:40 25 4
gpt4 key购买 nike

我有一个antd table我想在页脚中总结列。然而,我在让它们与我的专栏正确对齐时遇到了问题。我尝试使用 Row/Col 来使其匹配,但运气不佳。它还需要响应...

 <Table
columns={columns}
dataSource={tableData}
footer={
<Row>
<Col span={8}>
<strong>TOTALS:</strong>
</Col>
<Col span={2}>
123
</Col>
<Col span={3} />
<Col span={2}>
123
</Col>
<Col span={2} />
<Col span={2}>
123
</Col >
<Col span={8} />
</Row>
}
/>

enter image description here

有没有更好的方法来实现这个目标?

最佳答案

我在表组件中找到了 Antd 团队提供的很好的解决方案,看看希望这能解决您的问题。看看(https://codesandbox.io/s/summary-ant-design-demo-kw93t)

import ReactDOM from 'react-dom';
import 'antd/dist/antd.css';
import './index.css';
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,
},
];

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.',
});
}

ReactDOM.render(
<>
<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>
</>
);
}}
/>
</>,
document.getElementById('container'),
);

谢谢。

关于reactjs - antd 表总结,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48030648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com