当前位置: 首页 > news >正文

ElementUI table表格组件实现双击编辑单元格失去焦点还原,支持多单元格

在使用ElementUI table表格组件时有时需要双击单元格显示编辑状态,失去焦点时还原表格显示。
实现思路:

  • 在数据中增加isFocus:false.控制是否显示
  • 在table中用@cell-dblclick双击方法

先看效果:
在这里插入图片描述

上源码:在表格模板中用scope.row.isFocus && focusLabelName=='姓名1控制多个单元格显示

<el-table :data="tableData" border stripe style="width: 100%"  @cell-dblclick="tabClick"><el-table-column prop="date" label="Product Name" width="180"></el-table-column><el-table-column prop="address" label="地址"></el-table-column><el-table-column prop="price" label="姓名1"  width="180"><template slot-scope="scope"><el-input v-if="scope.row.isFocus && focusLabelName=='姓名1'" v-focus size="small" v-model="scope.row.price" @change="changeTrafOrigTaxAmount(scope.row)" @blur="blurInput(scope.row)"></el-input><span v-else>{{scope.row.price}}</span></template></el-table-column><el-table-column prop="price" label="姓名2"  width="180"><template slot-scope="scope"><el-input v-if="scope.row.isFocus && focusLabelName=='姓名2'" v-focus size="small" v-model="scope.row.price2" @change="changeTrafOrigTaxAmount(scope.row)" @blur="blurInput(scope.row)"></el-input><span v-else>{{scope.row.price2}}</span></template></el-table-column>
</el-table>

方法:

data: function () {return {tableData: [{date: '2016-05-02',name: '王小虎',address: '上海市普陀区金沙江路 1518 弄',price: 1000,price2: 1000,price3: 1000,isTransfer: true,rate: 0.3,amount: 1000,isFocus: false,}, {date: '2016-05-04',name: '王小虎',address: '上海市普陀区金沙江路 1517 弄',price: 1000,isTransfer: false,rate: 0.3,amount: 1000,isFocus: false,}, {date: '2016-05-01',name: '王小虎',address: '上海市普陀区金沙江路 1519 弄',price: 1000,price2: 1000,price3: 1000,isTransfer: true,rate: 0.3,amount: 1000,isFocus: false,}, {date: '2016-05-03',name: '王小虎',address: '上海市普陀区金沙江路 1516 弄',price: 1000,price2: 1000,price3: 1000,isTransfer: false,rate: 0.3,amount: 1000,isFocus: false,}],focusLabelName:''}},methods: {tabClick(row, column, cell, event){console.log(row, column, cell);row.isFocus = true;this.focusLabelName = column.label;},blurInput(row){row.isFocus = false}}
http://www.lryc.cn/news/303318.html

相关文章:

  • Java基于SpringBoot+Vue的图书管理系统
  • 【云安全】Hypervisor与虚拟机
  • JS文本加密方法探究
  • 推荐彩虹知识付费商城免授权7.0源码
  • 【天衍系列 04】深入理解Flink的ElasticsearchSink组件:实时数据流如何无缝地流向Elasticsearch
  • 一、ActiveMQ介绍
  • 【牛客】寒假训练营1 I-It‘s bertrand paradox. Again! 题解
  • 各种手型都合适,功能高度可定制,雷柏VT9PRO mini和VT9PRO游戏鼠标上手
  • sql建库,建表基础操作
  • 算法训练营day32,贪心算法6
  • CTR之行为序列建模用户兴趣:DIN
  • Java使用Redis实现分页功能
  • Qt标准对话框设置
  • 如何让Obsidian实现电脑端和安卓端同步
  • windows系统中jenkins构建报错提示“拒绝访问”
  • 服务器防火墙的应用技术有哪些?
  • 力扣:40. 组合总和 II
  • Java设计模式——责任链模式
  • c++面试
  • [ansible] playbook运用
  • MSSQL运用
  • linux命令--pidof
  • 计算机视觉发展的方向和潜在机会
  • Java Web(六)--XML
  • 智慧城市的新宠儿:会“思考”的井盖
  • Linux限定网络和工具环境下时间同步
  • SQL Server查询计划(Query Plan)——文本查询计划
  • 2024年2月的TIOBE指数,go语言排名第8,JAVA趋势下降
  • 机器人十大前沿技术(2023-2024年)
  • Spring: MultipartFile和File的区别