el-table 合并前四列:为什么第四列无法合并?(合并.前四.el.table.....)

wufei123 2025-01-26 阅读:64 评论:0
el-table合并部分成功部分不成功? 问题描述: 需要合并el-table中前4列的内容,但是第4列无法合并。 渲染代码:<el-table :data="waterData" border :span-me...

el-table 合并前四列:为什么第四列无法合并?

el-table合并部分成功部分不成功?

问题描述:

需要合并el-table中前4列的内容,但是第4列无法合并。

渲染代码:

PHP
<el-table :data="waterData" border :span-method="handleSpanM">
  <el-table-column align="center" width="65">
    <template slot-scope="scope">{{scope.row.name }}</template>
  </el-table-column>
  <el-table-column align="center" width="70" label="系数">
    <template slot-scope="scope">
      <el-input size="mini" class="" v-model="scope.row.factor"></el-input>
    </template>
  </el-table-column>
  <el-table-column align="center" width="120" label="等级分数">
    <template slot-scope="scope">
      <el-input size="mini" v-model="scope.row.grade"></el-input>
    </template>
  </el-table-column>
  <el-table-column align="center" width="180" label="符号选择">
    <template slot-scope="scope">
      <div class="symbol">
        <span style="display: none;">{{ scope.row.symbol }}</span>
        <span class="symbol_range"></span>
      </div>
    </template>
  </el-table-column>
  <el-table-column width="120" v-for="(column,index) in 6" :key="`column-${index}`">
    <template slot="header">
      <div>
        <el-input size="small" v-model="waterForm[`water${index + 1}_label`]">
        </el-input>
      </div>
    </template>
    <template slot-scope="scope">
      <div>
        <el-input size="small" v-model="waterForm[`water${index + 1}_factor`]"></el-input>
      </div>
    </template>
  </el-table-column>
</el-table>

解决方法:

可以使用自定义的合并方法来实现特定列的合并。

PHP
// 合并方法
merge(tableData) {
  this.companyArr = [];
  this.companyPos = 0;
  this.simpleArr = [];
  this.simplePos = 0;
  this.symbolArr = [];
  this.symbolPos = 0;
  for (var i = 0; i < tableData.length; i++) {
    if (i === 0) {
      // 第一行必须存在
      this.companyArr.push(1);
      this.companyPos = 0;
      this.simpleArr.push(1);
      this.simplePos = 0;
      this.symbolArr.push(1);
      this.symbolPos = 0;
    } else {
      // 第一列
      if (tableData[i].name === tableData[i - 1].name) {
        this.companyArr[this.companyPos] += 1;
        this.companyArr.push(0);
      } else {
        this.companyArr.push(1);
        this.companyPos = i;
      }

      // 第二列
      if (
        tableData[i].name === tableData[i - 1].name &&
        tableData[i].factor === tableData[i - 1].factor
      ) {
        this.simpleArr[this.simplePos] += 1;
        this.simpleArr.push(0);
      } else {
        this.simpleArr.push(1);
        this.simplePos = i;
      }

      // 第四列
      if (
        tableData[i].name === tableData[i - 1].name &&
        tableData[i].factor === tableData[i - 1].factor &&
        tableData[i].symbol === tableData[i - 1].symbol
      ) {
        this.symbolArr[this.symbolPos] += 1;
        this.symbolArr.push(0);
      } else {
        this.symbolArr.push(1);
        this.symbolPos = i;
      }
    }
  }
},

//合并方法
arraySpanMethod({ row, column, rowIndex, columnIndex }) {
  if (columnIndex === 0) {
    // 合并第一列
    const _row_1 = this.companyArr[rowIndex];
    const _col_1 = _row_1 > 0 ? 1 : 0; // 如果被合并了_row=0则它这个列需要取消
    return {
      rowspan: _row_1,
      colspan: _col_1,
    };
  } else if (columnIndex === 1) {
    // 合并第二列
    const _row_2 = this.simpleArr[rowIndex];
    const _col_2 = _row_2 > 0 ? 1 : 0;
    return {
      rowspan: _row_2,
      colspan: _col_2,
    };
  } else if (columnIndex === 3) {
    // 合并第四列
    const _row_3 = this.symbolArr[rowIndex];
    const _col_3 = _row_3 > 0 ? 1 : 0;
    return {
      rowspan: _row_3,
      colspan: _col_3,
    };
  }
},

完整示例:

PHP
<template>
  <el-table :data="waterData" border :span-method="arraySpanMethod">
    <el-table-column align="center" width="65">
      <template slot-scope="scope">{{scope.row.name }}</template>
    </el-table-column>
    <el-table-column align="center" width="70" label="系数">
      <template slot-scope="scope">
        <el-input size="mini" class="" v-model="scope.row.factor"></el-input>
      </template>
    </el-table-column>
    <el-table-column align="center" width="120" label="等级分数">
      <template slot-scope="scope">
        <el-input size="mini" v-model="scope.row.grade"></el-input>
      </template>
    </el-table-column>
    <el-table-column align="center" width="180" label="符号选择">
      <template slot-scope="scope">
        <div class="symbol">
          <span style="display: none;">{{ scope.row.symbol }}</span>
          <span class="symbol_range"></span>
        </div>
      </template>
    </el-table-column>
    <el-table-column width="120" v-for="(column,index) in 6" :key="`column-${index}`">
      <template slot="header">
        <div>
          <el-input size="small" v-model="waterForm[`water${index + 1}_label`]">
          </el-input>
        </div>
      </template>
      <template slot-scope="scope">
        <div>
          <el-input size="small" v-model="waterForm[`water${index + 1}_factor`]"></el-input>
        </div>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  data() {
    return {
      tableData:[
        {name:'降水(mm)',factor:'0.7',grade:'',symbol: '1','':'','':'','':'','':'','':'','':''},
        {name:'降水(mm)',factor:'0.7',grade:'',symbol: '1','':'','':'','':'','':'','':'','':''},
        {name:'降水(mm)',factor:'0.7',grade:'',symbol: '1','':'','':'','':'','':'','':'','':''},
        {name:'降水(mm)',factor:'0.7',grade:'',symbol: '1','':'','':'','':'','':'','':'','':''},
        {name:'风速(m/s)',factor:'0.5',grade:'',symbol: '0','':'','':'','':'','':'','':'','':''},
        {name:'风速(m/s)',factor:'0.5',grade:'',symbol: '0','':'','':'','':'','':'','':'','':''},

以上就是el-table 合并前四列:为什么第四列无法合并?的详细内容,更多请关注知识资源分享宝库其它相关文章!

版权声明

本站内容来源于互联网搬运,
仅限用于小范围内传播学习,请在下载后24小时内删除,
如果有侵权内容、不妥之处,请第一时间联系我们删除。敬请谅解!
E-mail:dpw1001@163.com

分享:

扫一扫在手机阅读、分享本文

发表评论
热门文章
  • BioWare埃德蒙顿工作室面临关闭危机,龙腾世纪制作总监辞职引关注(龙腾.总监.辞职.危机.面临.....)

    BioWare埃德蒙顿工作室面临关闭危机,龙腾世纪制作总监辞职引关注(龙腾.总监.辞职.危机.面临.....)
    知名变性人制作总监corrine busche离职bioware,引发业界震荡!外媒“smash jt”独家报道称,《龙腾世纪:影幢守护者》制作总监corrine busche已离开bioware,此举不仅引发了关于个人职业发展方向的讨论,更因其可能预示着bioware埃德蒙顿工作室即将关闭而备受关注。本文将深入分析busche离职的原因及其对bioware及游戏行业的影响。 Busche的告别信:挑战与感激并存 据“Smash JT”获得的内部邮件显示,Busche离职原...
  • boss直聘怎么取消面试预约 boss直聘上面试爽约了会怎么样(面试.爽约.预约.取消.boss.....)

    boss直聘怎么取消面试预约 boss直聘上面试爽约了会怎么样(面试.爽约.预约.取消.boss.....)
    求职宝典:boss直聘面试技巧及取消预约方法 各位求职者注意啦!在Boss直聘上,随意取消面试预约会留下爽约记录,影响后续求职!本文将指导您如何避免爽约,以及如何取消已预约的面试。 如何取消Boss直聘面试预约? 打开Boss直聘APP,进入“我的”页面。 点击“待面试”,查看面试日程。 选择需要取消的面试,点击“取消面试”按钮即可。 Boss直聘面试爽约的后果? 爽约行为会在HR端留下记录,影响您的求职成功率。其他HR也能看到您的不良记录,所以务必重视面试预约。...
  • 闪耀暖暖靡城永恒怎么样-闪耀暖暖靡城永恒套装介绍(闪耀.暖暖.套装.介绍.....)

    闪耀暖暖靡城永恒怎么样-闪耀暖暖靡城永恒套装介绍(闪耀.暖暖.套装.介绍.....)
    闪耀暖暖钻石竞技场第十七赛季“华梦泡影”即将开启!全新闪耀性感套装【靡城永恒】震撼来袭!想知道如何获得这套精美套装吗?快来看看吧! 【靡城永恒】套装设计理念抢先看: 设计灵感源于夜色中的孤星,象征着淡然、漠视一切的灰色瞳眸。设计师希望通过这套服装,展现出在虚幻与真实交织的夜幕下,一种独特的魅力。 服装细节考究,从面料的光泽、鞋跟声响到裙摆的弧度,都力求完美还原设计初衷。 【靡城永恒】套装设计亮点: 闪耀的绸缎与金丝交织,轻盈的羽毛增添华贵感。 这套服装仿佛是从无尽的黑...
  • 蛋仔派对2025最新皮肤兑换码汇总 最新皮肤兑换码一览(兑换.皮肤.最新.派对.汇总.....)

    蛋仔派对2025最新皮肤兑换码汇总 最新皮肤兑换码一览(兑换.皮肤.最新.派对.汇总.....)
    蛋仔派对2025最新皮肤兑换码大放送!游戏内新增多款皮肤兑换码,包含最新、福利和通用三种类型,助你轻松获取精美奖励! 赶紧来看看如何兑换吧! 兑换码列表: 最新兑换码: ccewndj4k4k、cdkqdfm4fh、peetnmp4ef、cdxymk8f67 福利兑换码: cca863ywtfa、eggy2310am、eggy2311gz、eggyeggy9wz 通用兑换码: pec74dkcty、jsrqkrrjmh、cd3wt7wrph、ccepn7d8cjf...
  • python怎么调用其他文件函数

    python怎么调用其他文件函数
    在 python 中调用其他文件中的函数,有两种方式:1. 使用 import 语句导入模块,然后调用 [模块名].[函数名]();2. 使用 from ... import 语句从模块导入特定函数,然后调用 [函数名]()。 如何在 Python 中调用其他文件中的函数 在 Python 中,您可以通过以下两种方式调用其他文件中的函数: 1. 使用 import 语句 优点:简单且易于使用。 缺点:会将整个模块导入到当前作用域中,可能会导致命名空间混乱。 步骤:...