element 表格编辑保存新增删除修改批量删除

这是一个关于使用Element UI组件库中表格组件进行数据管理的示例。内容包括选择、编辑、新增和删除功能的实现,涉及表格行的增删及批量操作。用户可以通过输入框编辑故障代码和描述,并通过按钮触发操作,如单个或批量增加记录,以及删除选定的记录。
摘要由CSDN通过智能技术生成

   <el-table :data="tabledatas"

                    @selection-change="handleSelectionChange"

                    style="width: 100%;margin-top:20px;">

            <el-table-column type="selection"

                             width="55">

            </el-table-column>

            <el-table-column type="index"

                             width="70"

                             :label="$t('common.sequence_number')">

            </el-table-column>

            <el-table-column :label="$t('askingInformation.failure_rate')">

              <template slot-scope="scope">

                <span>

                  <el-input size="mini"

                            maxlength="10"

                            :placeholder="$t('common.input')"

                            οninput="value=value.replace(/[^\w]/g,'')"

                            v-model.trim="scope.row.fault_code"></el-input>

                </span>

                <!-- <span v-else>{{scope.row.fault_code}}</span> -->

              </template>

            </el-table-column>

            <el-table-column :label="$t('askingInformation.describe')">

              <template slot-scope="scope">

                <span>

                  <el-input size="mini"

                            :placeholder="$t('common.input')"

                            v-model="scope.row.fault_description"></el-input>

                </span>

                <!-- <span v-else>{{scope.row.fault_description}}</span> -->

              </template>

            </el-table-column>

            <el-table-column prop=""

                             :label="this.$t('common.operation')"

                             min-width="80">

              <template slot-scope="scope">

                <!-- <el-button @click="edit(scope.row,scope.$index)">{{scope.row.show?`${$t('common.save')}`: `${$t('askingInformation.editor')}`}}</el-button> -->

                <!-- <el-button @click="cope(scope.row,scope.$index)">单个复制</el-button> -->

                <el-button class="btn"

                           type="primary"

                           @click="addAllNum">

                  <svg-icon icon-class="addfill"

                            class-name="button-icon"></svg-icon>

                  <!-- {{$t('askingInformation.a_single_increase')}} -->

                </el-button>

                <el-button class="btn"

                           @click="delect(scope.$index)">

                  <svg-icon icon-class="deletefill"

                            class-name="button-icon"></svg-icon>

                  <!-- {{$t('menu.delete')}} -->

                </el-button>

              </template>

            </el-table-column>

          </el-table>

 //单个新增

    addAllNum() {

      if (this.multipleSelection.length == 0) {

        let list = {

          fault_code: '',

          fault_description: '',

        }

        this.tabledatas.push(list)

      } else {

        this.multipleSelection.forEach((val, index) => {

          this.tabledatas.splice(index, 0, JSON.parse(JSON.stringify(val)))

        })

      }

    },

   //批量删除

    delectAll() {

      for (let i = 0; i < this.tabledatas.length; i++) {

        const element = this.tabledatas[i]

        element.id = i

      }

      if (this.multipleSelection.length == 0)

        this.$message.error(this.$t('askingInformation.choose_at_least_one'))

      this.multipleSelection.forEach((element) => {

        this.tabledatas.forEach((e, i) => {

          if (element.id == e.id) {

            this.tabledatas.splice(i, 1)

          }

        })

      })

      if (this.tabledatas.length == 0) {

        setTimeout(() => {

          this.addAllNum()

        }, 500)

      }

    },

 // //批量新增

    // addAll() {

    //   if (this.multipleSelection.length == 0) {

    //     let list = [

    //       {

    //         fault_code: '',

    //         fault_description: '',

    //       },

    //       {

    //         fault_code: '',

    //         fault_description: '',

    //       },

    //       {

    //         fault_code: '',

    //         fault_description: '',

    //       },

    //       {

    //         fault_code: '',

    //         fault_description: '',

    //       },

    //       {

    //         fault_code: '',

    //         fault_description: '',

    //       },

    //     ]

    //     list.forEach((item, index) => {

    //       this.tabledatas.push(item)

    //     })

    //   } else {

    //     this.multipleSelection.forEach((val, index) => {

    //       this.tabledatas.splice(index, 0, JSON.parse(JSON.stringify(val)))

    //     })

    //   }

    // },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值