• 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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    方法:

    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
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
  • 相关阅读:
    SpringBoot—日志文件
    车间静电消除不掉?静电接地桩来帮忙!
    一文读懂 协方差矩阵
    电子制造行业的数字化转型突破点在哪?精益制造是关键
    Leetcode66. 加一
    牛客 题解
    【云原生】k8s-----集群调度
    【边缘检测】基于蚁群算法实现图像边缘检测附matlab代码
    微服务架构的未来:跨边界的云原生整合
    Day 59 django ROM 多表查询
  • 原文地址:https://blog.csdn.net/tianlu930/article/details/136188705