欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue?element?ui表格相同數(shù)據(jù)合并單元格效果實例

 更新時間:2023年11月22日 10:04:47   作者:弈425  
工作中遇到需要根據(jù)單元格某個屬性合并,特此記錄下,下面這篇文章主要給大家介紹了關(guān)于vue?element?ui表格相同數(shù)據(jù)合并單元格效果的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下

先看效果  

前提是你的數(shù)據(jù)是扁平的數(shù)據(jù)因為要根據(jù)上下數(shù)據(jù)是否一樣才合并的  如果是子級數(shù)據(jù)需要改一下數(shù)據(jù)格式了

下面是數(shù)據(jù)的樣式

tableData: [{
          id: '1',
          name: '王小虎',
          amount1: '165',
          amount2: '3.2',
          amount3: 10
        }, {
          id: '1',
          name: '王小虎',
          amount1: '162',
          amount2: '4.43',
          amount3: 12
        }, {
          id: '1',
          name: '王we虎',
          amount1: '621',
          amount2: '1.9',
          amount3: 9
        }, {
          id: '2',
          name: '王we虎',
          amount1: '621',
          amount2: '2.2',
          amount3: 17
        }, {
          id: '3',
          name: '王小虎',
          amount1: '621',
          amount2: '4.1',
          amount3: 15
        }],

合并單元格的重點屬性就是 :summary-method="" 這個是關(guān)鍵

<el-table ref="tableRef" show-summary :summary-method="getSummaries" :span-method="handleSpanMethod"  :data="listData"  border style="width: 100%; margin-top: 5px">
      <el-table-column label="No." type="index" align="center" width="50"></el-table-column>
      <el-table-column prop="checkResult" label="Check result"> </el-table-column>
      <el-table-column prop="standardChineseName" label="Standard chinese name"> </el-table-column>
      <el-table-column prop="ingredientInciCtfaName" label="Ingredient INCI(CTFA) name"> </el-table-column>
      <el-table-column prop="RMInFormula" label="RM in formula(%)"> </el-table-column>
      <el-table-column prop="ingredientInRM" label="Ingredient in RM(%)"> </el-table-column>
      <el-table-column prop="ingredientInFormula" label="Ingredient in formula(%)"> </el-table-column>
      <el-table-column prop="purposeOfUse" label="Purpose of use"> </el-table-column>
      <el-table-column prop="templateUrl5" label="New RM" align="center" width="100"> </el-table-column>
    </el-table>
data() {
    return {
      listData: [],

      // 合并單元格
      column1Arr: [], // column1
      column1Index: 0, // column1索引

      column2Arr: [], // column2
      column2Index: 0, // column2索引

      column3Arr: [], // column3
      column3Index: 0, // column3索引

      column4Arr: [], // column4
      column4Index: 0, // column4索引

      column5Arr: [], // column5
      column5Index: 0, // column5索引

      column6Arr: [], // column6
      column6Index: 0, // column6索引

      column7Arr: [], // column7
      column7Index: 0, // column7索引
    }
  },
mergeTable(data) {
      if (data.length > 0) {
        for (var i = 0; i < data.length; i++) {
          if (i === 0) {
            // 第一行必須存在,以第一行為基準(zhǔn)  合并的數(shù)量根據(jù)直接需求改
            this.column1Arr.push(1) // column1
            this.column1Index = 0
            this.column2Arr.push(1) // column2
            this.column2Index = 0

            this.column3Arr.push(1) // column3
            this.column3Index = 0

            this.column4Arr.push(1) // column4
            this.column4Index = 0

            this.column5Arr.push(1) // column5
            this.column5Index = 0

            this.column6Arr.push(1) // column6
            this.column6Index = 0

            this.column7Arr.push(1) // column7
            this.column7Index = 0
          } else {
            // 判斷當(dāng)前元素與上一元素是否相同   
            // 我是根據(jù)第一個數(shù)據(jù)合并后續(xù)才可以合并 
            //如果是 根據(jù)當(dāng)前表格的前一列可以在每一個 column1++   后面添加上前一個表格的列            
            // 如果是只要相同就合并那就每個column 里面的條件直接當(dāng)前列就可以了
    
            // column1
            if (data[i].checkResult === data[i - 1].checkResult) {
              this.column1Arr[this.column1Index] += 1
              this.column1Arr.push(0)
            } else {
              this.column1Arr.push(1)
              this.column1Index = i
            }

            // column2
              if (data[i].standardChineseName === data[i - 1].standardChineseName && data[i].checkResult === data[i - 1].checkResult) {
                this.column2Arr[this.column2Index] += 1
                this.column2Arr.push(0)
              } else {
                this.column2Arr.push(1)
                this.column2Index = i
              }

              // column3
              if (data[i].ingredientInciCtfaName === data[i - 1].ingredientInciCtfaName && data[i].checkResult === data[i - 1].checkResult) {
                this.column3Arr[this.column3Index] += 1
                this.column3Arr.push(0)
              } else {
                this.column3Arr.push(1)
                this.column3Index = i
              }

              // column4
              if (data[i].RMInFormula === data[i - 1].RMInFormula && data[i].checkResult === data[i - 1].checkResult) {
                this.column4Arr[this.column4Index] += 1
                this.column4Arr.push(0)
              } else {
                this.column4Arr.push(1)
                this.column4Index = i
              }

              // column5
              if (data[i].ingredientInRM === data[i - 1].ingredientInRM && data[i].checkResult === data[i - 1].checkResult) {
                this.column5Arr[this.column5Index] += 1
                this.column5Arr.push(0)
              } else {
                this.column5Arr.push(1)
                this.column5Index = i
              }

              // column6
              if (data[i].ingredientInFormula === data[i - 1].ingredientInFormula && data[i].checkResult === data[i - 1].checkResult) {
                this.column6Arr[this.column6Index] += 1
                this.column6Arr.push(0)
              } else {
                this.column6Arr.push(1)
                this.column6Index = i
              }

              // column7
              if (data[i].purposeOfUse === data[i - 1].purposeOfUse && data[i].checkResult === data[i - 1].checkResult) {
                this.column7Arr[this.column7Index] += 1
                this.column7Arr.push(0)
              } else {
                this.column7Arr.push(1)
                this.column7Index = i
              }
          }
        }
      }
    },
    
    //我這里是在表格的第二列開始合并因為第一列是 序號 不可以合并  從第一個開始合并就把 下表
    //改為0  columnIndex === 0
    handleSpanMethod({ rowIndex, columnIndex }) {
      if (columnIndex === 1) {
        // 第二列 column2
        const _row_1 = this.column1Arr[rowIndex]
        const _col_1 = _row_1 > 0 ? 1 : 0
        return {
          rowspan: _row_1,
          colspan: _col_1,
        }
      } 
      else if (columnIndex === 2) {
        // 第三列 column3
        const _row_2 = this.column2Arr[rowIndex]
        const _col_2 = _row_2 > 0 ? 1 : 0
        return {
          rowspan: _row_2,
          colspan: _col_2,
        }
      } else if (columnIndex === 3) {
        // 第四列 column4
        const _row_3 = this.column3Arr[rowIndex]
        const _col_3 = _row_3 > 0 ? 1 : 0
        return {
          rowspan: _row_3,
          colspan: _col_3,
        }
      } else if (columnIndex === 4) {
        // 第五列 column5
        const _row_4 = this.column4Arr[rowIndex]
        const _col_4 = _row_4 > 0 ? 1 : 0
        return {
          rowspan: _row_4,
          colspan: _col_4,
        }
      } else if (columnIndex === 5) {
        // 第六列 column6
        const _row_5 = this.column5Arr[rowIndex]
        const _col_5 = _row_5 > 0 ? 1 : 0
        return {
          rowspan: _row_5,
          colspan: _col_5,
        }
      } else if (columnIndex === 6) {
        // 第七列 column7
        const _row_6 = this.column6Arr[rowIndex]
        const _col_6 = _row_6 > 0 ? 1 : 0
        return {
          rowspan: _row_6,
          colspan: _col_6,
        }
      } else if (columnIndex === 7) {
        // 第八列 column8
        const _row_7 = this.column7Arr[rowIndex]
        const _col_7 = _row_7 > 0 ? 1 : 0
        return {
          rowspan: _row_7,
          colspan: _col_7,
        }
      }
    },
//調(diào)取接口獲取數(shù)據(jù)
getList() {
      const prams = {
        taskId: this.taskId,
        formulaId: this.formulaId
      }
      this.$http({
        headers: {
          'Content-Type': 'application/json',
        },
        method: 'post',
        url: '/123123',
        data: prams,
      })
      .then(res=>{
        this.listData = res.data.records //給data變量賦值
        this.mergeTable(this.listData)//合并單元格傳入數(shù)據(jù)
      })
      //清空之前的數(shù)據(jù)  不清空 表格數(shù)據(jù)就會亂套
      this.column1Arr = []
      this.column1Index = 0
      this.column2Arr = []
      this.column2Index = 0
      this.column3Arr = []
      this.column3Index = 0
      this.column4Arr = []
      this.column4Index = 0
      this.column5Arr = []
      this.column5Index = 0
      this.column6Arr = []
      this.column6Index = 0
      this.column7Arr = []
      this.column7Index = 0
    },

完整代碼

<template>
  <div>
    <el-table ref="tableRef" show-summary :summary-method="getSummaries" :span-method="handleSpanMethod"  :data="listData"  border style="width: 100%; margin-top: 5px">
      <el-table-column label="No." type="index" align="center" width="50"></el-table-column>
      <el-table-column prop="checkResult" label="Check result"> </el-table-column>
      <el-table-column prop="standardChineseName" label="Standard chinese name"> </el-table-column>
      <el-table-column prop="ingredientInciCtfaName" label="Ingredient INCI(CTFA) name"> </el-table-column>
      <el-table-column prop="RMInFormula" label="RM in formula(%)"> </el-table-column>
      <el-table-column prop="ingredientInRM" label="Ingredient in RM(%)"> </el-table-column>
      <el-table-column prop="ingredientInFormula" label="Ingredient in formula(%)"> </el-table-column>
      <el-table-column prop="purposeOfUse" label="Purpose of use"> </el-table-column>
      <el-table-column prop="templateUrl5" label="New RM" align="center" width="100"> </el-table-column>
    </el-table>
  </div>
</template>
  
<script>
export default {
  components: {},
  data() {
    return {
      listData: [],

      // 合并單元格
      column1Arr: [], // column1
      column1Index: 0, // column1索引

      column2Arr: [], // column2
      column2Index: 0, // column2索引

      column3Arr: [], // column3
      column3Index: 0, // column3索引

      column4Arr: [], // column4
      column4Index: 0, // column4索引

      column5Arr: [], // column5
      column5Index: 0, // column5索引

      column6Arr: [], // column6
      column6Index: 0, // column6索引

      column7Arr: [], // column7
      column7Index: 0, // column7索引
    }
  },
  computed: {},
  created() {
    this.getList()
  },
  mounted() {
    
  },
  methods: {
    getList() {
      const prams = {
        taskId: this.taskId,
        formulaId: this.formulaId
      }
      this.$http({
        headers: {
          'Content-Type': 'application/json',
        },
        method: 'post',
        url: '/1123123123',
        data: prams,
      })
      .then(res=>{
        this.listData = res.data.records//給data中的變量賦值 把res.data.records換成自己
//的據(jù)接口 更改一下數(shù)據(jù)的字段 便可以直接使用了  
        this.mergeTable(this.listData)//合并單元格傳入數(shù)據(jù)
      })
      //清空之前的數(shù)據(jù)
      this.column1Arr = []
      this.column1Index = 0
      this.column2Arr = []
      this.column2Index = 0
      this.column3Arr = []
      this.column3Index = 0
      this.column4Arr = []
      this.column4Index = 0
      this.column5Arr = []
      this.column5Index = 0
      this.column6Arr = []
      this.column6Index = 0
      this.column7Arr = []
      this.column7Index = 0
    },
    mergeTable(data) {
      if (data.length > 0) {
        for (var i = 0; i < data.length; i++) {
          if (i === 0) {
            // 第一行必須存在,以第一行為基準(zhǔn)
            this.column1Arr.push(1) // column1
            this.column1Index = 0
            this.column2Arr.push(1) // column2
            this.column2Index = 0

            this.column3Arr.push(1) // column3
            this.column3Index = 0

            this.column4Arr.push(1) // column4
            this.column4Index = 0

            this.column5Arr.push(1) // column5
            this.column5Index = 0

            this.column6Arr.push(1) // column6
            this.column6Index = 0

            this.column7Arr.push(1) // column7
            this.column7Index = 0
          } else {
            // 判斷當(dāng)前元素與上一元素是否相同
            // column1
            if (data[i].checkResult === data[i - 1].checkResult) {
              this.column1Arr[this.column1Index] += 1
              this.column1Arr.push(0)
            } else {
              this.column1Arr.push(1)
              this.column1Index = i
            }

            // column2
              if (data[i].standardChineseName === data[i - 1].standardChineseName && data[i].checkResult === data[i - 1].checkResult) {
                this.column2Arr[this.column2Index] += 1
                this.column2Arr.push(0)
              } else {
                this.column2Arr.push(1)
                this.column2Index = i
              }

              // column3
              if (data[i].ingredientInciCtfaName === data[i - 1].ingredientInciCtfaName && data[i].checkResult === data[i - 1].checkResult) {
                this.column3Arr[this.column3Index] += 1
                this.column3Arr.push(0)
              } else {
                this.column3Arr.push(1)
                this.column3Index = i
              }

              // column4
              if (data[i].RMInFormula === data[i - 1].RMInFormula && data[i].checkResult === data[i - 1].checkResult) {
                this.column4Arr[this.column4Index] += 1
                this.column4Arr.push(0)
              } else {
                this.column4Arr.push(1)
                this.column4Index = i
              }

              // column5
              if (data[i].ingredientInRM === data[i - 1].ingredientInRM && data[i].checkResult === data[i - 1].checkResult) {
                this.column5Arr[this.column5Index] += 1
                this.column5Arr.push(0)
              } else {
                this.column5Arr.push(1)
                this.column5Index = i
              }

              // column6
              if (data[i].ingredientInFormula === data[i - 1].ingredientInFormula && data[i].checkResult === data[i - 1].checkResult) {
                this.column6Arr[this.column6Index] += 1
                this.column6Arr.push(0)
              } else {
                this.column6Arr.push(1)
                this.column6Index = i
              }

              // column7
              if (data[i].purposeOfUse === data[i - 1].purposeOfUse && data[i].checkResult === data[i - 1].checkResult) {
                this.column7Arr[this.column7Index] += 1
                this.column7Arr.push(0)
              } else {
                this.column7Arr.push(1)
                this.column7Index = i
              }
          }
        }
      }
    },

    handleSpanMethod({ rowIndex, columnIndex }) {
      if (columnIndex === 1) {
        // 第二列 column2
        const _row_1 = this.column1Arr[rowIndex]
        const _col_1 = _row_1 > 0 ? 1 : 0
        return {
          rowspan: _row_1,
          colspan: _col_1,
        }
      } 
      else if (columnIndex === 2) {
        // 第三列 column3
        const _row_2 = this.column2Arr[rowIndex]
        const _col_2 = _row_2 > 0 ? 1 : 0
        return {
          rowspan: _row_2,
          colspan: _col_2,
        }
      } else if (columnIndex === 3) {
        // 第四列 column4
        const _row_3 = this.column3Arr[rowIndex]
        const _col_3 = _row_3 > 0 ? 1 : 0
        return {
          rowspan: _row_3,
          colspan: _col_3,
        }
      } else if (columnIndex === 4) {
        // 第五列 column5
        const _row_4 = this.column4Arr[rowIndex]
        const _col_4 = _row_4 > 0 ? 1 : 0
        return {
          rowspan: _row_4,
          colspan: _col_4,
        }
      } else if (columnIndex === 5) {
        // 第六列 column6
        const _row_5 = this.column5Arr[rowIndex]
        const _col_5 = _row_5 > 0 ? 1 : 0
        return {
          rowspan: _row_5,
          colspan: _col_5,
        }
      } else if (columnIndex === 6) {
        // 第七列 column7
        const _row_6 = this.column6Arr[rowIndex]
        const _col_6 = _row_6 > 0 ? 1 : 0
        return {
          rowspan: _row_6,
          colspan: _col_6,
        }
      } else if (columnIndex === 7) {
        // 第八列 column8
        const _row_7 = this.column7Arr[rowIndex]
        const _col_7 = _row_7 > 0 ? 1 : 0
        return {
          rowspan: _row_7,
          colspan: _col_7,
        }
      }
    }
}
</script>

總結(jié) 

到此這篇關(guān)于vue element ui表格相同數(shù)據(jù)合并單元格的文章就介紹到這了,更多相關(guān)element ui相同數(shù)據(jù)合并單元格內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue實現(xiàn)城市列表選擇功能

    vue實現(xiàn)城市列表選擇功能

    這篇文章主要介紹了vue實現(xiàn)城市列表選擇功能,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-07-07
  • Vue 進(jìn)階之路(三)

    Vue 進(jìn)階之路(三)

    這篇文章主要介紹了Vue 進(jìn)階之路,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • 使用vue打包時vendor文件過大或者是app.js文件很大的問題

    使用vue打包時vendor文件過大或者是app.js文件很大的問題

    這篇文章主要介紹了使用vue打包時vendor文件過大或者是app.js文件很大問題的解決方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-06-06
  • vue3響應(yīng)式對象的api超全實例詳解

    vue3響應(yīng)式對象的api超全實例詳解

    可以把數(shù)據(jù)變成響應(yīng)式api的方法叫做響應(yīng)式api,下面這篇文章主要給大家介紹了關(guān)于vue3響應(yīng)式對象api的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-05-05
  • vue使用i18n實現(xiàn)國際化的方法詳解

    vue使用i18n實現(xiàn)國際化的方法詳解

    這篇文章主要給大家介紹了關(guān)于vue使用i18n如何實現(xiàn)國際化的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用vue具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • 淺談Vue數(shù)據(jù)綁定的原理

    淺談Vue數(shù)據(jù)綁定的原理

    本篇文章主要介紹了淺談Vue數(shù)據(jù)綁定的原理,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • Vue中路由的使用方法實例詳解

    Vue中路由的使用方法實例詳解

    本文為大家介紹Vue中路由的使用方法,包括安裝路由創(chuàng)建路由并導(dǎo)出以及在應(yīng)用實例中使用vue-router的相關(guān)知識,本文結(jié)合實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2024-02-02
  • vue指令實現(xiàn)數(shù)字和大寫中文實時互轉(zhuǎn)

    vue指令實現(xiàn)數(shù)字和大寫中文實時互轉(zhuǎn)

    這篇文章主要介紹了如何使用Vue指令實現(xiàn)在用戶輸入數(shù)字失焦后實時將數(shù)字轉(zhuǎn)為大寫中文,聚焦的時候?qū)⒋髮懼形霓D(zhuǎn)為數(shù)字以便用戶繼續(xù)修改,需要的可以參考下
    2024-12-12
  • vue后臺系統(tǒng)管理項目之角色權(quán)限分配管理功能(示例詳解)

    vue后臺系統(tǒng)管理項目之角色權(quán)限分配管理功能(示例詳解)

    這篇文章主要介紹了vue后臺系統(tǒng)管理項目-角色權(quán)限分配管理功能,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-09-09
  • vue實現(xiàn)目錄樹結(jié)構(gòu)

    vue實現(xiàn)目錄樹結(jié)構(gòu)

    這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)目錄樹結(jié)構(gòu),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03

最新評論