Customize React Antd table header with table data

走远了吗. 提交于 2020-01-05 04:56:21

问题


In my React project, I need to customize antd table header as follows

I have added sample code bellow.

I need to have Sum of the amount in the header of the Amount column

Sample Code:

https://codesandbox.io/embed/great-sun-534cd


回答1:


You can use title function like this for get total of amount fields

const columns = [

    {
      title: () => { 
        var total = 0;
        for(var i=0;i<data.length;i++){
          total += data[i].amount;
        }
        return <div>total {total}</div>;
      } ,
      dataIndex: "date",
      width: 200
    },
    {
      title: "Amount",
      dataIndex: "amount",
      width: 100
    }
  ];

Example link here https://codesandbox.io/s/festive-wiles-st6wl?fontsize=14



来源:https://stackoverflow.com/questions/56697735/customize-react-antd-table-header-with-table-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!