ngzorro实现表格的rowspan合并

目标效果:

 实现过程:

后端返回的数据格式如下,这种格式如果直接展示并不能实现我们需要的效果,所以需要先将数据格式进行转换。

 转换如下:

if (res.status === StatusEnum.SUCCESS) {
        this.pageList = res.datas;
        const opreatArry = [];
        if (this.pageList.length > 0) {
          this.pageList.forEach(item => {
            if (item.relations && item.relations.length > 0) {
              item.relations.forEach((subitem, index) => {
                let obj: {};
                obj = JSON.parse(JSON.stringify(item));
                obj['rowspan'.toString()] = item.relations.length;
                if (index !== 0) {
                  obj['isshow'.toString()] = false;
                } else {
                  obj['isshow'.toString()] = true;
                }
                obj['relationsId'.toString()] = subitem.id;
                obj['productName'.toString()] = subitem.productName;
                obj['select'.toString()] = subitem.select;
                opreatArry.push(obj);
              });
            }
          });
        }
        this.pageListOpreat = opreatArry;
        console.log(this.pageListOpreat)
      }

转换结果如下:

最后在页面中实现:

     <nz-table
        nzBordered
        [nzData]="pageListOpreat"
        [nzFrontPagination]="false"
        [nzShowPagination]="false"
        [nzLoadingDelay]="1"
      >
        <thead>
        <tr>
          <th nzWidth="120px">课程名称</th>
          <th>学院名称</th>
          <th>待选产品</th>
          <th nzWidth="100px">选择方式</th>
          <th nzWidth="80px">选择状态</th>
          <th nzWidth="200px">选择时间</th>
          <th nzWidth="100px">操作</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let item of pageListOpreat; let i = index;">
          <ng-container *ngIf="item.isshow">
            <td [rowSpan]="item.rowspan">{{item.courseName}}</td>
            <td [rowSpan]="item.rowspan">{{item.collegeName}}</td>
            <td>{{item.productName}}</td>
            <td [rowSpan]="item.rowspan">{{item.rowspan}}选{{item.productSelectNumber}} 
            </td>
            <td>{{item.select?'是':'否'}}</td>
            <td [rowSpan]="item.rowspan">{{item.selectTime?item.selectTime:'—'}}</td>
            <td [rowSpan]="item.rowspan">
              <span *ngIf="item.selectTime">-</span>
              <span *ngIf="!item.selectTime">选择产品</span>
            </td>
          </ng-container>
          <ng-container *ngIf="!item.isshow">
            <td>{{item.productName}}</td>
            <td>{{item.select?'是':'否'}}</td>
          </ng-container>
        </tr>
        </tbody>
      </nz-table>

记录。 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值