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
        }
    }

相关推荐

  1. elementui表格实现单个单元触发事件

    2024-02-21 13:10:02       52 阅读
  2. 编辑el-table的单元数据

    2024-02-21 13:10:02       60 阅读
  3. vue+elementUI实现指定列的单元编辑

    2024-02-21 13:10:02       40 阅读
  4. vue3+ts实现表格单元编辑功能

    2024-02-21 13:10:02       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-21 13:10:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-21 13:10:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-02-21 13:10:02       87 阅读
  4. Python语言-面向对象

    2024-02-21 13:10:02       96 阅读

热门阅读

  1. shell关联数组用法

    2024-02-21 13:10:02       50 阅读
  2. webScoket实时通讯聊天

    2024-02-21 13:10:02       58 阅读
  3. CSS的全局值 initial inherit revert overlay unset

    2024-02-21 13:10:02       49 阅读
  4. MFC中不同编码格式内容的写入

    2024-02-21 13:10:02       48 阅读
  5. 手写table表格(一表头多数据)

    2024-02-21 13:10:02       51 阅读
  6. C/C++三角函数math.h库详解

    2024-02-21 13:10:02       49 阅读
  7. ThreadLocal(4):ThreadLocal的核心方法源码

    2024-02-21 13:10:02       49 阅读
  8. 代码随想录算法训练营第三八天 | 动态规划

    2024-02-21 13:10:02       63 阅读