el-table 简单的行内编辑,单行可编辑

 

<div class="btns" style="margin-bottom: 2vh;">
        <el-button  type="primary" icon="el-icon-plus" size="small" @click="addRow()">新 增</el-button>
      </div>
      <el-table :data="dataList"  class="table-fixed" style="width: 100%">
        <el-table-column prop="columnTest" label="示例字段" width="130">
          <template slot-scope="scope">
            <el-input  v-model="scope.row.columnTest" :disabled="!(scope.row.isEdit || scope.row.isAdd)" />
          </template>
        </el-table-column>
        <el-table-column prop="capitalAmount" align="center" label="操作" width="120">
         <template slot-scope="scope">
            <el-button @click="save(scope.row)" v-show="scope.row.isAdd" type="text" size="small" icon="el-icon-edit">保存(新增)</el-button>
            <el-button @click="deleteRow(scope.$index)" v-show="scope.row.isAdd" type="text" size="small" icon="el-icon-delete">取消(新增)</el-button>
            <el-button @click="update(scope.row)" v-show="scope.row.isEdit" type="text" size="small" icon="el-icon-edit">保存(修改)</el-button>
            <el-button @click="cancel(scope.row)" v-show="scope.row.isEdit" type="text" size="small" icon="el-icon-delete">取消(修改)</el-button>
            <el-button @click="edit(scope.row)" v-show="!scope.row.isEdit && !scope.row.isAdd" type="text" size="small" icon="el-icon-edit">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>

细分位表格上面的新增(新增空白行)按钮、行内的保存,取消,编辑等按钮。

点击新增->新增行,行可编辑(行内按钮 保存(新增),取消(新增)) ,点取消,删除行

点击新增->新增行,行可编辑(行内按钮 保存(新增),取消(新增)) ,点保存,执行新增逻辑,按钮变为编辑,行不可编辑

点编辑 -> 行可编辑 (行内按钮 保存(修改),取消(修改)),点取消,删除行,按钮变为编辑,行不可编辑

点保存,执行修改逻辑,按钮变为编辑,行不可编辑

需要给dataList绑定 isEdit,isAdd属性,已实现以上功能

  data() {
    return {
       dataList:[]
}



 addRow() {
      let row = {
        isEdit : false,
        isAdd : true
      }
      this.dataList.push(row) 
    },
    //新增取消 - 删除行
    deleteRow(index) {
      this.dataList.splice(index, 1)
    },
    //修改取消 
    cancel(row) {
      row.isEdit = false
    },
    edit(row) {
      row.isEdit = true
    },
    save(row) {
      row.isEdit = false
      row.isAdd = false
      //保存逻辑
    },
    update(row) {
      row.isEdit = false
      //修改逻辑
    },

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值