Vue+EleMentUI實(shí)現(xiàn)el-table-colum表格select下拉框可編輯功能實(shí)例
說明:
在進(jìn)行采購入庫的過程中,有必要對(duì)表格中的一行進(jìn)行快速編輯保存,節(jié)省時(shí)間,提高工作效率!,而不是每次編輯都要彈窗才可編輯源碼:https://gitee.com/charlinchenlin/store-pos
效果圖:
1、在data定義supplier數(shù)組等元素
data() { return { suppliers:[], //保存供應(yīng)商數(shù)據(jù) showInput: "", //用來判斷是否顯示哪個(gè)單元格 oldData: {}, //用來存修改前的數(shù)據(jù) currentData: {}, //用來保存新的數(shù)據(jù) } },
2、為el-table表格單擊和雙擊添加tableDbEdit事件
<el-table :data="dataList" size="mini" v-loading="dataListLoading" @selection-change="selectionChangeHandle" style="width: 100%;" @cell-click="tableDbEdit" @cell-dblclick="tableDbEdit" height="320" :header-cell-style="{ background: '#fcfcfc', color: '#606266', height:'36px'}"> <el-table-column type="selection" header-align="center" align="center" width="50"> </el-table-column> ------ </el-table>
控制是否顯示select下拉框
tableDbEdit(row, column, event) { this.showInput = column.property + row.inboundId; this.oldData[column.property] = row[column.property]; },
3、為供應(yīng)商列添加下拉框
如果showInput的值與當(dāng)前的inboundId相同,則顯示下拉選項(xiàng),否則顯示數(shù)據(jù)信息
<el-table-column prop="supplierName" header-align="center" align="center" label="供應(yīng)商名稱" width="150" show-overflow-tooltip> <template slot-scope="scope"> <el-select size="mini" @focus="getSuppliers()" @click="getSuppliers()" @change='blurInput(scope.row, "supplierName", scope.row.supplierName)' v-model="scope.row.supplierName" clearable v-if="showInput == `supplierName${scope.row.inboundId}`" placeholder="請(qǐng)選擇"> <el-option v-for="item in suppliers" :key="item.supplierId" :label="item.supplierName" :value="item.supplierName"> </el-option> </el-select> <span v-else class="active-input">{{scope.row.supplierName}}</span> </template> </el-table-column>
聚焦或單擊時(shí)獲取供應(yīng)商數(shù)據(jù)
async getSuppliers() { const res = await this.$http({ url: `/product/supplier/getSupplies`, method: 'get', params: this.$http.adornParams() }) let data = res.data if (data && data.code === 0) { this.suppliers = data.data } },
觸發(fā)change事件時(shí)給當(dāng)前列賦值,并設(shè)置供應(yīng)商信息
// 當(dāng)input失去光標(biāo)后進(jìn)行的操作 async blurInput(row, name, value) { // 判斷數(shù)據(jù)是否有所改變,如果數(shù)據(jù)有改變則調(diào)用修改接口 if (this.oldData[name] != value) { row[name] = value } this.showInput = "" this.currentData = row if(name === 'supplierName'){ this.setSuppliers(row) } }, setSuppliers(row) { for (let index in this.suppliers) { let item = this.suppliers[index] if (row.supplierName === item.supplierName) { row.supplierId = item.supplierId return } } },
4、保存當(dāng)前列,成功后重新加載數(shù)據(jù)
async saveHandle(row) { console.log("saveHandle row===", row) row.status = row.status ? 1 : 0 const res = await this.$http({ url: `/purchase/purchasesinboundorder/update`, method: 'post', data: this.$http.adornData(row) }); let data = res.data if (data && data.code !== 0) { row.status = !row.status; return this.$message.error('修改失敗!'); } this.$message.success('更新成功!'); this.getDataList(); },
5、定義v-focus
directives: { // 通過自定義指令實(shí)現(xiàn)的表單自動(dòng)獲得光標(biāo)的操作 focus: { inserted: function(el) { if (el.tagName.toLocaleLowerCase() == "input") { el.focus() } else { if (el.getElementsByTagName("input")) { el.getElementsByTagName("input")[0].focus() } } el.focus() } }, focusTextarea: { inserted: function(el) { if (el.tagName.toLocaleLowerCase() == "textarea") { el.focus() } else { if (el.getElementsByTagName("textarea")) { el.getElementsByTagName("textarea")[0].focus() } } el.focus() } } },
總結(jié)
到此這篇關(guān)于Vue+EleMentUI實(shí)現(xiàn)el-table-colum表格select下拉框可編輯功能的文章就介紹到這了,更多相關(guān)el-table-colum表格select下拉框內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue 自定義組件 v-model雙向綁定、 父子組件同步通信的多種寫法
父子組件通信,都是單項(xiàng)的,很多時(shí)候需要雙向通信。這篇文章主要介紹了vue 自定義組件 v-model雙向綁定、 父子組件同步通信,需要的朋友可以參考下2017-11-11Vue實(shí)現(xiàn)雙向綁定的原理以及響應(yīng)式數(shù)據(jù)的方法
這篇文章主要介紹了Vue實(shí)現(xiàn)雙向綁定的原理以及響應(yīng)式數(shù)據(jù)的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-07-07在項(xiàng)目中封裝axios的實(shí)戰(zhàn)過程
這篇文章主要給大家介紹了關(guān)于如何在項(xiàng)目中封裝axios的相關(guān)資料,axios 請(qǐng)求的封裝,無非是為了方便代碼管理,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2021-09-09Vue設(shè)置長時(shí)間未操作登錄自動(dòng)到期返回登錄頁
這篇文章主要介紹了Vue設(shè)置長時(shí)間未操作登錄以后自動(dòng)到期返回登錄頁,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2020-01-01ArcGis?API?for?js在vue.js中的使用示例詳解
這篇文章主要為大家介紹了ArcGis?API?for?js在vue.js中的使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08