element-ui table表格双击行内编辑

这篇具有很好参考价值的文章主要介绍了element-ui table表格双击行内编辑。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

行内双击编辑的本质:点击后input框出现,保存后span标签出现

<el-dialog
               class="dialog"
               :visible.sync="splitBillDialog2"
               :close-on-click-modal="false"
               :close-on-press-escape="false"
               :append-to-body="true"
               width="800px"
               height="400px"
               @close ="resetForm"
    >
        <template>
            <el-table
                    ref="splitBillTable"
                    :data="spliteBilltableData"
                    border
                    highlight-current-row
                    show-summary
                    :summary-method="getSummaries"
                    @current-change="handleCurrentChange"
                    @row-dblclick="rowDblclick"
                    :cell-style="splitBillTableStyle"
                    style="width: 100%"
                    height="400px"
                    :row-class-name="tableRowClassName"
            >
                <el-table-column :show-overflow-tooltip="true" property="billUtil" label="开票件数" width="120px">
                    <template slot-scope="scope">
                        <el-input v-if="isEditSplit[scope.$index]" size="small" v-model="scope.row.billUtil">
                            <span v-if="isEditSplit[scope.$index]">{{scope.row.billUtil}}</span>
                        </el-input>
                        <span v-if="!isEditSplit[scope.$index]">{{scope.row.billUtil}}</span>
                    </template>
                </el-table-column>
<!--                <el-table-column label="操作" min-width="50px" class-name="tablebtns" fixed="right">-->
<!--                    <template slot-scope="scope">-->
<!--                        <el-button v-if="!isEditSplit[scope.$index]" @click="editSplit(scope.$index)" type="text">编辑</el-button>-->
<!--                        <el-button v-if="isEditSplit[scope.$index]" @click="saveSplit(scope.$index)" type="text">保存</el-button>-->
<!--                    </template>-->
<!--                </el-table-column>-->
            </el-table>
        </template>
        <div slot="footer" class="dialog-footer">
            <el-row style="margin: 0;">
                <el-col :span="24" align="center" class="table-panel">
                    <div v-if="isDoubleClick" style="display: inline">
                        <el-button v-if="isEditSplitBtn &&isDoubleClick" @click="saveSplit()" type="primary">保存</el-button>
                        <el-button v-if="!isEditSplitBtn &&isDoubleClick" @click="cancelSplit()" type="primary">撤销</el-button>
                    </div>
                    <el-button @click="splitBillDialog2 = false">取 消</el-button>
                    <el-button class="confirmBtn" type="primary" @click="preSubmitStockBill()">确 定</el-button>
                </el-col>
            </el-row>
        </div>
    </el-dialog>

data:{
	spliteBilltableData:[
         {mainCompany:'xxx',
             prodName:'xxx',
             prodCode:'xxx',
             billUtil:'xxx',
             billQat:'xxx',
             billAmount:'xxx',
             discountAmount:'xxx',
             totalPrice:'xxx',
             prodUnit:'xxx',
             netPrice:'xxx'
         }
     ],
     currentRow: null,
     currentRow2: null,
     beforeCheckRow2: null,
     isCurrentRow2EditFlag:false,
     isEditSplit:[false],
     index:'',
     index2:'',
     isEditSplitBtn:false,
     isDoubleClick:false,
}
handleCurrentChange(val){
   // console.log("val:",val)
    this.currentRow = val;
},
tableRowClassName({row, rowIndex}){
   row.index = rowIndex;
},
//双击编辑
rowDblclick(row, column){
    this.isEditSplitBtn=true
    this.isDoubleClick=true
    //如果编辑行和选中行不是同一行,则代表编辑了下一行,保存之前编辑的数据
    if (row.index !== this.index) {
        this.$set(this.isEditSplit, this.index, false);
    }
    this.index = row.index;
    this.$set(this.isEditSplit, this.index, true);
},
//保存按钮
saveSplit(){
    this.$set(this.isEditSplit, this.index, false);
    this.isDoubleClick=false
},
//关闭dialog框后重置
resetForm(){
    this.index2 = '';
    this.index = '';
    this.isEditSplit = [false];
    this.isCurrentRow2EditFlag = false;
    this.beforeCheckRow2 = null;
},

如果有编辑某一行的某列其他列随之变化的需求,则需要将上一步选中行存下来,不然双击后选中行就变了,随之修改的值也会产生错误

rowDblclick2(row, column){
    this.isEditSplitBtn=true
    this.isDoubleClick=true
    if (row.index !== this.index2) {   
        if (this.isCurrentRow2EditFlag){     //是否编辑过      
            var price = xxxx;//要改变的值           
            this.$set(this.beforeCheckRow2,"billAmount",price)
        }
        this.beforeCheckRow2=this.currentRow2
        this.isCurrentRow2EditFlag=true
        this.$set(this.isEditSplit, this.index2, false);
    }
    this.index2 = row.index;
    this.$set(this.isEditSplit, this.index2, true);
},

此外,因为用到了tableRowClassName({row, rowIndex}){ row.index = rowIndex;},,所以导致表格的每一行元素多了一个index,有些项目的后端是以类的形式接收,所以会报错,这时需要在发起请求前去掉index

rows.forEach((item)=>{
   for (let key in item) {
        if (key !== 'index') {
            newItems[key] = item[key];
        }
    }
    totalRows.push(deepCopy(newItems))
})

:cell-style="splitBillTableStyle"用法:表格元素样式修改文章来源地址https://www.toymoban.com/news/detail-558278.html

 splitBillTableStyle({ row, column, rowIndex, columnIndex }){
	if (column.property === "xxx") {  //要改样式的列名,这里是改变某列的颜色
	    return 'background-color:#50E3A5;border-bottom:1px solid white'
	}
},

到了这里,关于element-ui table表格双击行内编辑的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • element-ui表格Table详解

    先给大家展示一下效果 Table 属性  属性名 说明 类型 可选值 默认值 data 显示的数据 array — — height Table 的高度, 默认为自动高度。 如果 height 为 number 类型,单位 px;如果 height 为 string 类型,则这个高度会设置为 Table 的 style.height 的值,Table 的高度会受控于外部样式。 s

    2024年02月07日
    浏览(35)
  • Element-ui 动态Table表格

    最近在做相关需求,感觉太多的重复代码,网上也很多这种动态的,写的很好,所以我借鉴了很多大佬的动态table表格,结合需求,完成了我自己需要的table。 1.config文件夹相关配置文件 2.一个用来配置的’pageTable.vue’文件 其实table 表格里面的align也可以动态,我这里偷懒了

    2024年02月11日
    浏览(32)
  • Vue Element-ui Table表格排序

    一.表格中有时候会有排序的需求,如果只针对当前页进行排序,那么前端就可以实现排序,在对应需要排序的字段中,使用sortable字段即可。 二.存在分页的情况时,前端仅仅使用sortable当前页排序已经不能满足我们的需求,无法对所有数据进行排序。这时候我们就要使用后端

    2024年02月11日
    浏览(39)
  • element-ui table 设置表格滚动条位置

    场景: 在切换不同页面时(被 keep-alive 缓存的组件间切换),页面中的element-ui table的滚动条位置没有停留在原来的位置。目前需要切换不同的页面返回来后,滚动条保持在原来的位置。 代码:

    2024年02月11日
    浏览(43)
  • 【element-ui】table表格底部合计自定义配置

    目录  带合计的表格设置  自定义方法  getSummaries   【element-ui】table表格底部合计自定义配置,最近做管理系统用到饿了么UI,用到了table表格合计需求,常用的table底部,有时候不是所有内容都需要合计,比如上图这个编号是数字,但是不需要合计计算处理的,这时候就需

    2024年02月11日
    浏览(38)
  • element-ui实现表格每行可以编辑数据

    每行可以编辑数据可以不使用弹窗实现修改数据的功能,这里使用到element-ui框架 效果图如下: 代码如下: 可获取到编辑的数据 这里展示axios.post请求来实现编辑功能

    2024年02月12日
    浏览(42)
  • element-ui table 表格控件实现单选功能

    今天遇到一个需求,感觉挺简单的,需求如下: 就是一个表格,在表格的前面加上一个选择框,注意: 只能单选 然后我就去element ui上粘代码: 虽然element ui上有对应的单选表格,可是并不符合我的需求 然后我又发现下面有一个多选的表格,样式虽然相似,可是还是不符合我

    2024年02月11日
    浏览(43)
  • vue监听element-ui的table表格滚动事件

    这篇文章主要是讲述“如何监听element-ui table滚动事件”,按我自己尝试的方法去实现。 需求分析: 前两天做项目遇到一个问题,数据量大,然后表格渲染的很慢,而且很卡怎么办?有什么优化的方式? 那无非就是两种方法。 先加载一屏表格的数据,之后触底加载新的数据

    2024年02月12日
    浏览(43)
  • vue+element-ui+springboot 在线表格编辑

    方法: 编辑excel 格式为需要的样子,另存为html 打开files文件,复制html部分代码和样式到vue文件 将需要编辑的部分使用控件填入 代码: 特别地: 服装列数可变,需要动态变换,同时有的可编辑,有的不可编辑 增加表格行数,可通过增加memberList 数据进行动态添加和删除,无

    2024年01月24日
    浏览(38)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包