1

我正在尝试在 antd 中准备一个具有动态行跨度的表(数据将是动态的)

我有如下数据。

想显示如下。你能帮忙吗?

[{"col1":"temp1","col2":"1","col3":"x"}, {"col1":"temp1","col2":"1","col3":"y"}, {"col1":"temp1","col2":"2","col3":"z"}, {"col1":"temp2","col2":"3","col3":"a"}];

在此处输入图像描述

4

1 回答 1

0

我们可以编写自定义渲染方法来解决这个问题。样本 :

render: (value, row, index) => {
        const obj = {
          children: value,
          props: {},
        };
        if (index >= this.state.branch_new_index) {
          for (let i = 0; index + i !== metrics.length
                && value === metrics[index + i].branch  && 
                metrics[index].product === metrics[index + i].product; i += 1) {
            obj.props.rowSpan = i + 1;
            this.state.branch_count = i + 1;
          }
          this.state.branch_new_index = index + this.state.branch_count;
          if (index + 1 >= metrics.length) {
            this.state.branch_new_index = 0;
          }
        } else {
          obj.props.rowSpan = 0;
          if (index + 1 >= metrics.length) {
            this.state.branch_new_index = 0;
          }
        }
        return obj;
      },
于 2019-10-25T02:48:15.177 回答