• elementui——表格的相同内容单元格合并


    在今天工作中遇到了相同单元格需要合并的一个需求,实现记录如下。

    实现效果:

    任务要求:

    对表中体系这一列相同的体系进行合并。

    思路:
    定义一个空数组:[]
    定义一个变量:0
    遍历数据如果有相同数据 在空数组添加一个0(相同数据的起始位加1),不相同在数据push 一个1(变量改成当前索引)

    Table部分代码:

     <el-table ref="TaskListDistributionDetailTable" border :data="value.dataList" class="materialInfoTable clear-input-v" :span-method="objectSpanMethod">
                                <el-table-column type="index" align="center" label="序号" width="60">
                                    <template slot-scope="scope">
                                        {{scope.$index+1}}
                                    </template>
                                </el-table-column>
                                <el-table-column align="center" label="体系" min-width="120">
                                    <template slot-scope="scope">  
                                        <span>{{scope.row.systemTypeName}}</span>
                                    </template>
                                </el-table-column> 
                                <el-table-column align="center" label="部门" min-width="120">
                                    <template slot-scope="scope">  
                                        <span>{{scope.row.deptName}}</span>
                                    </template>
                                </el-table-column> 
                                <el-table-column align="left" label="年度考核得分" min-width="100">
                                    <template slot-scope="scope">  
                                        <span>{{scope.row.assessmentScore}}</span>     
                                    </template>
                                </el-table-column>
                                <el-table-column align="left" label="考核排名" min-width="100">
                                    <template slot-scope="scope"> 
                                        <span>{{scope.row.assessmentRank}}</span>    
                                    </template>
                                </el-table-column>
                                <el-table-column align="left" label="扣分原因" min-width="300">
                                    <template slot-scope="scope"> 
                                        <span>{{scope.row.deductionReason}}</span>      
                                    </template>
                                </el-table-column>
                                <el-table-column align="left" label="备注" min-width="300">
                                    <template slot-scope="scope"> 
                                        <span>{{scope.row.remark}}</span>      
                                    </template>
                                </el-table-column>  
                            </el-table>
    View Code

    Data部分代码:

      data: function () {
                return { 
                    spanArr:[], 
                };
            },
    Methods部分代码:
     objectSpanMethod({ row, column, rowIndex, columnIndex }) {
                    if (columnIndex === 1) {
                      if(this.spanArr[rowIndex]){
                          return {
                              rowspan:this.spanArr[rowIndex],
                              colspan:1
                          }
                      }else{
                          return {
                              rowspan: 0,
                              colspan: 0
                          }
                      }
                  }
              },
              flitterData:function () { 
                        let contactDot = 0;
                        let spanArr = [];
                        $this.value.dataList.forEach((item, index) => {
                            if (index === 0) { 
                                spanArr.push(1)
                            } else {
    //注释:
    systemTypeName 是对应体系,value.dataList 对应table绑定的数据源
    if (item.systemTypeName === this.value.dataList[index - 1].systemTypeName) {
                                    spanArr[contactDot] += 1;
                                    spanArr.push(0)
                                } else {
                                    contactDot = index
                                    spanArr.push(1)
                                }
                            }
                        })
                        this.spanArr = spanArr;
              }, 

    在合适的地方调用 flitterData方法  即可,我在项目中是获取数据源之后调用的

    原文:https://blog.csdn.net/weixin_44202166/article/details/110471420

    参考写法,方式调用与原文不同

  • 相关阅读:
    JMeter学习-016-思路篇之-山重水复柳暗花明
    JMeter学习-015-JMeter 断言之-Bean Shell Assertion
    JMeter学习-014-JMeter 配置元件实例之
    Fiddler-008-简单模拟性能测试
    Fiddler-007-修改HTTP请求响应数据
    Fiddler-006-修改HTTP请求参数
    JMeter学习-013-JMeter 逻辑控制器之-如果(If)控制器
    JMeter学习-012-JMeter 配置元件之-HTTP Cookie管理器-实现 Cookie 登录
    JMeter学习-011-JMeter 后置处理器实例之
    JMeter学习-010-JMeter 配置元件实例之
  • 原文地址:https://www.cnblogs.com/wofeiliangren/p/14993493.html
Copyright © 2020-2023  润新知