国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

element-ui添加動態(tài)表格并合計行合并行操作

這篇具有很好參考價值的文章主要介紹了element-ui添加動態(tài)表格并合計行合并行操作。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

項目開發(fā)過程中,我們有時候會遇到表格里面數(shù)據(jù)進行動態(tài)添加修改刪除的操作,表格里面我們也會經(jīng)常遇到合并單元格和合計累加計算行的數(shù)據(jù)。這里我們就簡單的記錄一下實際場景的運用!

最終實現(xiàn)的效果圖如下:

element-ui添加動態(tài)表格并合計行合并行操作
注意:這里的新增操作人不能重復(fù)添加,新增的時候有刪除操作,有編輯的數(shù)據(jù)進來的時候表格里面才會顯示編輯文字。

1,添加動態(tài)表格
return {
	// 表格數(shù)據(jù)
	 productivityForm: {
        qualityinspectorTable: []
     },
     // 添加操作人和動態(tài)表格里面的輸入框數(shù)據(jù)
     qualityinspectorForm: {
       qualityinspectorId: '',
       weChatproductNumber: '',
       shortmeddageproductNumber: '',
       telephoneproductNumber: ''
     },
     productivityFormRules: {},
     // 操作人下拉框
     qualityinspectorOptions: [
       { name: '李佳琪', qualityinspectorId: 1 },
       { name: '李向明', qualityinspectorId: 2 },
       { name: '王天成', qualityinspectorId: 3 },
       { name: '陳天', qualityinspectorId: 4 }
     ],
     // 點擊編輯下標
	editCurrentRowIndex: ''
     
}
// 添加操作人事件
addqualityinspectorClick () {
      if (!this.qualityinspectorForm.qualityinspectorId) {
        this.$message.warning('請先選擇操作人再進行新增操作!')
      } else {
        const obj = JSON.parse(JSON.stringify(this.qualityinspectorForm))
        if (this.productivityForm.qualityinspectorTable.find(e => e.qualityinspectorId === obj.qualityinspectorId)) {
          this.$message.warning('該操作人已存在,請勿重復(fù)添加')
        } else {
          this.productivityForm.qualityinspectorTable.push(obj)
          this.qualityinspectorForm.qualityinspectorId = ''
          this.qualityinspectorForm.weChatproductNumber = ''
          this.qualityinspectorForm.shortmeddageproductNumber = ''
          this.qualityinspectorForm.telephoneproductNumber = ''
        }
      }
    },
2,刪除表格行數(shù)據(jù)
deleteproducivity (index) {
   this.productivityForm.qualityinspectorTable.splice(index, 1)
 },
3, 編輯操作
// 點擊編輯判斷是否有重復(fù)數(shù)據(jù)
handleEditproducivity (type, index) {
   if (this.editCurrentRowIndex !== '' && !type) {
     this.$message.warning('請先確定您當前的修改項')
   } else {
     if (!type) {
       this.editCurrentRowIndex = index
     }
   }
 },
// 編輯提交保存操作(校驗非空數(shù)據(jù))
handleEditsave (row) {
  if (!row.telephoneproductNumber) {
    this.$message.warning('電話生產(chǎn)力不能為空!')
    return false
  } else if (!row.weChatproductNumber) {
    this.$message.warning('微信生產(chǎn)力不能為空!')
    return false
  } else if (!row.shortmeddageproductNumber) {
    this.$message.warning('短信生產(chǎn)力不能為空!')
    return false
  } else {
    this.$confirm('是否確認編輯操作嗎?', '警告', {
      confirmButtonText: '確定',
      cancelButtonText: '取消',
      type: 'warning'
    }).then(() => {
      const options = {
        qualityId: row.qualityId,
        telephoneproductNumber: row.telephoneproductNumber,
        weChatproductNumber: row.weChatproductNumber,
        shortmeddageproductNumber: row.shortmeddageproductNumber
      }
      this.$store.dispatch('tasks/PatientFollowUpSubmit', options).then(res => {
        this.$message.success('編輯成功')
        this.editCurrentRowIndex = ''
      })
    }).catch(() => {
      this.$message.info('已取消操作')
    })
  }
},
4,提交保存操作
submitForm (formName) {
   this.$refs[formName].validate((valid) => {
     if (valid) {
       const optionsdata = {
         ...this.productivityForm
       }
       console.log(optionsdata, 'sss')
       //   this.$store.dispatch('tasks/DoctorInfoSubmit', {
       //     TaskId: this.$route.query.id,
       //     ...this.productivityForm
       //   }).then(res => {
       //     this.$emit('getDoctorTaskDetails')
       //   })
     } else {
       return false
     }
   })
 },
5,頁面顯示內(nèi)容
<template>
  <div class="productivity-info-panel">
    <el-form class="productbox" :model="productivityForm" :rules="productivityFormRules" 	ref="productivityForm" label-width="150px" :inline="false">
      <el-form-item label="操作人">
        <el-select
          clearable
          filterable
          v-model="qualityinspectorForm.qualityinspectorId"
          placeholder="請選擇操作人">
          <el-option
            v-for="(item, index) in qualityinspectorOptions"
            :key="index"
            :label="item.name"
            :value="item.qualityinspectorId">
          </el-option>
        </el-select>
        <el-button style="margin-left: 20px;" type="primary" @click="addqualityinspectorClick" icon="el-icon-plus">新增操作人</el-button>
      </el-form-item>
      <div class="producivity-table">
        <el-table
          size="mini"
          :data="productivityForm.qualityinspectorTable"
          id="tables"
          :summary-method="getSummaries"
          show-summary
          style="width: 100%;">
          <el-table-column
            prop="qualityinspectorId"
            align="center"
            label="操作人">
            <template slot-scope="scope">
              <span>{{ scope.row.qualityinspectorId && (qualityinspectorOptions.find(e => e.qualityinspectorId === scope.row.qualityinspectorId)).name }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="telephoneproductNumber"
            align="center"
            label="電話生產(chǎn)力(天)">
            <template slot-scope="scope">
              <el-input-number placeholder="請輸入電話生產(chǎn)力" v-if="editCurrentRowIndex === scope.$index || !scope.row.qualityId"
                size="small" :step="1" step-strictly :min="0" v-model="scope.row.telephoneproductNumber"></el-input-number>
              <span v-else>{{ scope.row.telephoneproductNumber }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="weChatproductNumber"
            align="center"
            label="微信生產(chǎn)力(周)">
            <template slot-scope="scope">
              <el-input-number placeholder="請輸入微信生產(chǎn)力" v-if="editCurrentRowIndex === scope.$index || !scope.row.qualityId"
                size="small" :step="1" step-strictly :min="0" v-model="scope.row.weChatproductNumber"></el-input-number>
              <span v-else>{{ scope.row.weChatproductNumber }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="shortmeddageproductNumber"
            align="center"
            label="短信生產(chǎn)力(周)">
            <template slot-scope="scope">
              <el-input-number placeholder="請輸入短信生產(chǎn)力" v-if="editCurrentRowIndex === scope.$index || !scope.row.qualityId"
                size="small" :step="1" step-strictly :min="0" v-model="scope.row.shortmeddageproductNumber"></el-input-number>
              <span v-else>{{ scope.row.shortmeddageproductNumber }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="操作">
            <template slot-scope="scope">
              <el-button
                @click="handleEditproducivity(editCurrentRowIndex === scope.$index, scope.$index)"
                type="text"
                size="small">
                <span v-if="editCurrentRowIndex === scope.$index" @click="handleEditsave(scope.row)">保存</span>
                <span v-else-if="!!scope.row.qualityId">編輯</span>
              </el-button>
              <el-button type="text" style="color: red;" v-if="!scope.row.producivityId" @click="deleteproducivity(scope.$index)">刪除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="edit-doctor-btn">
        <el-button type="primary" @click="submitForm('productivityForm')">提交信息</el-button>
      </div>
    </el-form>
  </div>
</template>

6,表格合計和合并單元格操作

1,el-table里面添加: id=“tables” :summary-method=“getSummaries” show-summary 很重要!?。。。?/p>

<el-table :data="tableData" id="tables" :summary-method="getSummaries" show-summary>
1,合并單元

watch監(jiān)聽事件

watch: {
		//監(jiān)聽tableData
		tableData: {
			// 立即監(jiān)聽
			immediate: true,
			handler() {
				this.$nextTick(() => {
					const tds = document.querySelectorAll('#tables .el-table__footer-wrapper tr>td');
				    // colSpan合并列  這里打印一下看一下
			    	console.log(tds)
					tds[0].colSpan = 3;  // 這里是要合并幾行
					tds[0].style.textAlign = 'center';
					tds[1].style.display = 'none'; // 上述合并3行也就對應(yīng)的隱藏到第3個格子
					tds[2].style.display = 'none';
// 這里注意一下  要合并幾行就隱藏到第幾個格子,我合并3個格子,第0個格子是 合計 字段不用隱藏,后面兩個要隱藏因為是合并3個嘛,  我在這踩過坑 哭死
				});
			}
		}
	},
2,合計行計算

下面是計算直接官網(wǎng)的方法一樣的文章來源地址http://www.zghlxwxcb.cn/news/detail-511099.html

getSummaries(param) {
	   const { columns, data } = param;
	   const sums = [];
	   columns.forEach((column, index) => {
		if (index === 0) {
			sums[index] = '合計:';
			return;
		}else if(index === 1||index === 2){//只有這里改了一下
			// sums[index] = 'N/A';
			return;
		}
	       const values = data.map(item => Number(item[column.property]));
	       if (!values.every(value => isNaN(value))) {
			sums[index] = values.reduce((prev, curr) => {
				const value = Number(curr);
				if (!isNaN(value)) {
					return prev + curr;
				} else {
					return prev;
				}
	           }, 0);
	       sums[index];
		} else {
			sums[index] = 'N/A';
		}
	});
	return sums;
	},

到了這里,關(guān)于element-ui添加動態(tài)表格并合計行合并行操作的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 論element-ui表格的合并行和列(巨細節(jié))

    論element-ui表格的合并行和列(巨細節(jié))

    ? 作為一個后端來寫前端屬實是痛苦、講真的、剛開始我是真不想用餓了么的這個合并行和列、因為太語焉不詳了、看著頭疼、后來發(fā)現(xiàn)好像我沒得選、只好硬著頭皮上了。 效果圖: 代碼: 這里只展示關(guān)鍵代碼 先看看它們是怎么完成這個的: ? 首先,看似是合并了行、實

    2023年04月13日
    瀏覽(18)
  • vue2&Element-ui實現(xiàn)表格單元格合并

    vue2&Element-ui實現(xiàn)表格單元格合并

    由于項目需要實現(xiàn)單元格合并目前只是單頁沒有做分頁處理先上效果圖 看下數(shù)據(jù)結(jié)構(gòu) Element table提供的api arraySpanMethod columnIndex=0表示從第一列開始 rowIndex表示需要操作的行數(shù) 同濟醫(yī)院加上合計有12行從0開始=11 判斷條件是rowIndex余12===0 我們打印一下 或者改成 表示從0開始到1

    2024年02月12日
    瀏覽(37)
  • element-ui 表格(table)合并表頭下面合并列且可以收縮展開

    百度了一大堆,發(fā)現(xiàn)了首行不能合并,想到了用dom做,找到了下面這個鏈接 1、表頭合并 —— 給table添加屬性:header-cell-style=\\\"headerStyle\\\",里面給首行設(shè)置跨行 element-ui表頭合并 - ^Mao^ - 博客園 2、表內(nèi)合并 ——?給table添加屬性:span-method=\\\"arraySpanMethod\\\",里面設(shè)置合并 Element - The wor

    2024年02月16日
    瀏覽(96)
  • vue中Element-ui 表格 (Table)合并行、列單元格

    vue中Element-ui 表格 (Table)合并行、列單元格

    先在el-table里加個屬性:span-method綁定方法objectSpanMethod(),這個用來把你想合并的列根據(jù)你寫的邏輯來合并,再寫個getSpanArr(),這個寫合并的邏輯。 加一個屬性兩個方法,然后在獲取表格數(shù)據(jù)的時候調(diào)用一下getSpanArr(),示例代碼寫了四個邏輯,根據(jù)id相同合并,根據(jù)id和其他字段

    2024年02月10日
    瀏覽(25)
  • Element-ui 動態(tài)Table表格

    Element-ui 動態(tài)Table表格

    最近在做相關(guān)需求,感覺太多的重復(fù)代碼,網(wǎng)上也很多這種動態(tài)的,寫的很好,所以我借鑒了很多大佬的動態(tài)table表格,結(jié)合需求,完成了我自己需要的table。 1.config文件夾相關(guān)配置文件 2.一個用來配置的’pageTable.vue’文件 其實table 表格里面的align也可以動態(tài),我這里偷懶了

    2024年02月11日
    瀏覽(21)
  • 給 element-ui 表格的表頭添加icon圖標

    給 element-ui 表格的表頭添加icon圖標

    el-table icon圖標 的設(shè)置,使用? slot=\\\"header\\\" ?插槽,然后直接通過設(shè)置類名為? el-icon-iconName ?來使用即可。 效果展示:

    2024年02月16日
    瀏覽(31)
  • element-ui表格自定義動態(tài)列

    element-ui表格自定義動態(tài)列

    實現(xiàn)效果 具體功能 拖拽表頭改變寬度 限制最小寬度, 實時保存設(shè)置。 隱藏列 選中列隱藏, 不顯示在表格中。 “勾選” 列和\\\"操作\\\" 列不可隱藏, 并且不包含在列控制組件中。 隱藏后, 無論是否凍結(jié)均不顯示。有特殊標識則要另外做判斷。 列凍結(jié) 開啟時, 表示選中列靠左凍結(jié)

    2024年01月24日
    瀏覽(24)
  • [element-ui] el-table表格合并 span-method

    element 中表格合并 span-method 函數(shù)詳解

    2024年02月13日
    瀏覽(31)
  • element-ui 表格一行顯示多行內(nèi)容并實現(xiàn)多行內(nèi)某一行列合并

    element-ui 表格一行顯示多行內(nèi)容并實現(xiàn)多行內(nèi)某一行列合并

    這是加上邊框的, 去掉邊框后這個表格看著更明顯一點,表格一行放多行內(nèi)容,并讓第二行進行列合并,第一行不合并 該方法其實就是普通的列合并,只不過使用了row和col使效果看著像是第一行沒合并,第二行才合并

    2024年02月11日
    瀏覽(24)
  • element-ui/view-ui表格的合并行和列的多種方法(超級詳細)

    element-ui/view-ui表格的合并行和列的多種方法(超級詳細)

    vue的這兩個組件庫的表格的行和列的合并寫法是一樣的,都是通過span-method方法可以實現(xiàn)的;下面我們就以view ui的表格組件為例; 該方法參數(shù)為 4 個對象: row: 當前行 column: 當前列 rowIndex: 當前行索引 columnIndex: 當前列索引 該函數(shù)可以返回一個包含兩個元素的數(shù)組,第一個元

    2024年04月14日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包