当前位置: 代码网 > it编程>编程语言>Javascript > elementui的table根据是否符合需求合并列的实现代码

elementui的table根据是否符合需求合并列的实现代码

2024年05月18日 Javascript 我要评论
elementui的table根据是否符合需求合并列 <el-table :data="tabledata" border style="width: 100%;" :span-method="

elementui的table根据是否符合需求合并列

在这里插入图片描述

 <el-table :data="tabledata" border style="width: 100%;" :span-method="objectspanmethodauto">
          <!-- 空状态 -->
          <template slot="empty">
            <div><img src="@/assets/images/nodata.png" /></div>
            <span>暂无数据</span>
          </template>
          <el-table-column type="index" label="序号" width="80" align="center">
          </el-table-column>
          <el-table-column label="年度" align="center" prop="year">
          </el-table-column>
          <el-table-column prop="regionname" label="行政区划" align="center">
          </el-table-column>
          <el-table-column align="center">
            <template slot="header">
              <div class="header-con">(万人)</div>
              <div class="header-name">农业人口数量</div>
            </template>
            <template slot-scope="scope">
              <div>{{ scope.row.ruralpopnum }}</div>
            </template>
          </el-table-column>
          <el-table-column align="center">
            <template slot="header">
              <div class="header-con">(万人)</div>
              <div class="header-name">城镇人口数量</div>
            </template>
            <template slot-scope="scope">
              <div>{{ scope.row.urbanpopnum }}</div>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="{ row }">
              <el-button type="text" size="small" class="operation" style="color: #2372ed;" @click="handleedittable(row)">编辑</el-button>
              <el-button type="text" size="small" class="operation" style="color: #2372ed;" @click="handledelete(row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
data: function () {
      return {
       spanarr:[],
       tabledata:[]
	}
}
getlist() {
      getpoplist(this.query).then((res) => {
        this.totalcount = res.total;
        this.tabledata = res.rows;
        let contactdot = 0;
        let spanarr = [];
        this.tabledata.foreach((item, index) => {
          if (index === 0) {
            console.log(spanarr);
            spanarr.push(1);
          } else {
            if (item.year === this.tabledata[index - 1].year) {
              spanarr[contactdot] += 1;
              spanarr.push(0);
            } else {
              contactdot = index;
              spanarr.push(1);
            }
          }
        });
        this.spanarr = spanarr;
      });
    },
  // 合并行
    objectspanmethodauto({ row, column, rowindex, columnindex }) {
      console.log("点击:", row, column, rowindex, columnindex);
      if (columnindex == 1 || columnindex == 5) {
        if (this.spanarr[rowindex]) {
          return {
            rowspan: this.spanarr[rowindex],
            colspan: 1,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
    },

到此这篇关于elementui的table根据是否符合需求合并列的文章就介绍到这了,更多相关elementui的table合并列内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com