简体   繁体   English

使用表数据自定义 React Antd 表头

[英]Customize React Antd table header with table data

In my React project, I need to customize antd table header as follows在我的React项目中,需要自定义antd表头如下在此处输入图片说明

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 https://codesandbox.io/embed/great-sun-534cd

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://codesandbox.io/s/festive-wiles-st6wl?fontsize=14

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM