ant-design/components/table/demo/summary.md
二货机器人 72a7ba618f
New Table (#19678)
* chore: update rc-table

* add basic table style

* checked all logic

* checkbox support disabled

* selection style

* selection support radio

* add selections support

* selection extra style

* select all locale

* sorter logic

* add more desc

* init Filter hooks

* init filter hooks

* update style

* filter style

* filter style

* fix filter

* sort control

* ajax it

* add expandedable css

* expandable view style

* fixed style

* border style

* empty style

* fix pagination style

* add fixed demo

* un-comment

* clean up

* fix filter check logic

* fix overflow & ellipsis conflict

* fix tes

* adjust scroll shadow

* fix border fixed style

* add part of test case

* add filter test part

* more test case

* issue related test

* filter test

* adjust pagination logic

* fix pagination test case

* all selection test case

* table sorter test case

* table basic test

* fix test case

* update faq

* update expandable doc

* add v4 doc

* add summary docs

* more demo

* fix selection

* update snapshot

* update test case

* fix ff styling

* update rc-table

* update snapshot

* update snapshot

* fix lint

* fix style lint

* fix style

* update snapshot

* update desc

* fix missing icon
2019-11-15 14:35:25 +08:00

1.7 KiB

order title
29
en-US zh-CN
Summary 总结栏

zh-CN

通过 summary 设置总结栏。

en-US

Set summary content by summary prop.

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,
  },
];

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 (
        <>
          <tr>
            <th>Total</th>
            <td>
              <Text type="danger">{totalBorrow}</Text>
            </td>
            <td>
              <Text>{totalRepayment}</Text>
            </td>
          </tr>
          <tr>
            <th>Balance</th>
            <td colSpan={2}>
              <Text type="danger">{totalBorrow - totalRepayment}</Text>
            </td>
          </tr>
        </>
      );
    }}
  />,
  mountNode,
);