Customize React Antd table header with table data

前端 未结 1 566
一整个雨季
一整个雨季 2021-01-24 11:41

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 Am

相关标签:
1条回答
  • 2021-01-24 11:53

    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

    0 讨论(0)
提交回复
热议问题