antd 如何合并行?

setlist: [
    {
    "setlength": '',            //  number 长度, 这个字段有些数据有,有些没有
    province: "",
    city: "",
    name: "V2",
    weight: 100,
    new_domain: "qn-v2.xiaoying.tv",
    country: "",
    original_domain: "v2.xiaoying.tv",
    snstype: null,
    platform: 1,
    state: 1,
    create_time: "2017-03-21, 12:01:30",
    scheduling_time: "00:00:00",
    service_provider: "",
    id: 17194
    }, {
    province: "",
    city: "",
    name: "V4",
    weight: 100,
    new_domain: "ali-v4d.xiaoying.tv",
    country: "",
    original_domain: "v4d.xiaoying.tv",
    snstype: null,
    platform: 1,
    state: 1,
    create_time: "2017-03-21, 12:01:42",
    scheduling_time: "00:00:00",
    service_provider: "",
    id: 17190
    } 。。。。。
]

这个数组作为antd的table组件的数据源,第一列的字段为 setlength,如果第1,第11, 第30个数据有setlength字段,则将第一列的第一到第十行合并,第十一到第二十九行合并,合并后出现单元格错乱,下面是我的代码,大神帮我看看啊

const columns = [

 {
   title: '任务执行时间',
   dataIndex: 'scheduling_time',
   key: 'scheduling_time',
   width: 150,
   render: (text, record, index) => {
     const obj = {
        children: text,
        props: {},
      };
      if (record.setlength) {
        obj.props.rowSpan = record.setlength;
      }
      // These two are merged into above cell
      // if (index === 3) {
      //   obj.props.rowSpan = 0;
      // }
      // if (index === 4) {
      //   obj.props.colSpan = 0;
      // }
      return obj;
   },
阅读 5.7k
1 个回答

你只设置了record.setlength存在时所在行的rowSpan,record.setlength不存时也要设置;
比如:

if (record.setlength) {
    obj.props.rowSpan = record.setlength;
} else {
    obj.props.rowSpan = 0; // 这里根据需要设置,一般默认是1,不需要设为0
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题