zoukankan      html  css  js  c++  java
  • element-ui 的 el-table,点击单元格可编辑

    <template>
     <div id="ailse_box">
      <div>
       <el-table
        style=" 100%;"
        :row-key="get_row_key"
        @cell-click="cell_click"
        :row-class-name="table_row_class_name"
        :data="tableData
       >
        <el-table-column type="selection" align="center" :reserve-selection="true"> </el-table-column>
        <el-table-column label="通道ID" align="center">
         <template slot-scope="scope">
          <div
           class="cell_btn"
           v-if="scope.row.index === cell_click_index && cell_click_label === '通道ID'"
          >
           <el-input
            size="mini"
            maxlength="300"
            placeholder="请输入通道ID"
            v-model="scope.row.taskid"
           />
           <el-button
            type="primary"
            size="mini"
            icon="el-icon-edit"
            circle
            @click="determine_modify(scope.row)"
           ></el-button>
           <el-button
            type="warning"
            size="mini"
            icon="el-icon-close"
            circle
            @click="cancel('cancel_edit')"
           ></el-button>
          </div>
          <span v-else>{{ scope.row.taskid }}</span>
         </template>
        </el-table-column>
        <el-table-column align="center" label="通道名称">
         <template slot-scope="scope">
          <div
           class="cell_btn"
           v-if="scope.row.index === cell_click_index && cell_click_label === '通道名称'"
          >
           <el-input
            size="mini"
            maxlength="300"
            placeholder="请输入通道名称"
            v-model="scope.row.taskname"
           />
           <el-button
            type="primary"
            size="mini"
            icon="el-icon-edit"
            circle
            @click="determine_modify(scope.row)"
           ></el-button>
           <el-button
            type="warning"
            size="mini"
            icon="el-icon-close"
            circle
            @click="cancel('cancel_edit')"
           ></el-button>
          </div>
          <span v-else>{{ scope.row.taskname }}</span>
         </template>
        </el-table-column>
        <el-table-column align="center" label="分析地址">
         <template slot-scope="scope">
          <div
           class="cell_btn"
           v-if="scope.row.index === cell_click_index && cell_click_label === '分析地址'"
          >
           <el-input
            size="mini"
            maxlength="300"
            placeholder="请输入分析地址"
            v-model="scope.row.address"
           />
           <el-button
            type="primary"
            size="mini"
            icon="el-icon-edit"
            circle
            @click="determine_modify(scope.row)"
           ></el-button>
           <el-button
            type="warning"
            size="mini"
            icon="el-icon-close"
            circle
            @click="cancel('cancel_edit')"
           ></el-button>
          </div>
          <span v-else>{{ scope.row.address }}</span>
         </template>
        </el-table-column>
        <el-table-column align="center" label="序号">
         <template slot-scope="scope">
          <div
           class="cell_btn"
           v-if="scope.row.index === cell_click_index && cell_click_label === '序号'"
          >
           <el-input size="mini" maxlength="300" placeholder="请输入序号" v-model="scope.row.no" />
           <el-button
            type="primary"
            size="mini"
            icon="el-icon-edit"
            circle
            @click="determine_modify(scope.row)"
           ></el-button>
           <el-button
            type="warning"
            size="mini"
            icon="el-icon-close"
            circle
            @click="cancel('cancel_edit')"
           ></el-button>
          </div>
          <span v-else>{{ scope.row.no }}</span>
         </template>
        </el-table-column>
       </el-table>
      </div>
     </div>
    </template>
    
    <script>
    export default {
     data() {
      return {
       tableData: [], // 表格数据
       cell_click_index: null, // 点击的单元格
       cell_click_label: '', // 当前点击的列名
      }
     },
     methods: {
      // 把每一行的索引放进row
      table_row_class_name({ row, rowIndex }) {
       row.index = rowIndex
      },
      // 单元格点击事件
      cell_click(row, column, cell, event) {
       this.cell_click_index = row.index
       this.cell_click_label = column.label
       switch (column.label) {
        case 'taskid':
         this.cell_click_index = row.index
         this.cell_click_label = column.label
         break
        case 'taskname':
         this.cell_click_index = row.index
         this.cell_click_label = column.label
         break
        default:
         return
       }
      },
      // 确定修改
      determine_modify(row) {
       console.log(row)
      },
     },
      // 点击取消
      cancel(status) {
       switch (status) {
        case 'cancel_edit':
         this.cell_click_index = null
         this.cell_click_label = ''
         break
        default:
         break
       }
      },
    }
    </script>

  • 相关阅读:
    performance benchmark : memcached vs Kyoto Tycoon
    Adhesive框架系列文章应用程序信息中心模块实现
    神奇的Redis
    使用代码测试ASP.NET MVC2执行流程
    linq2sql代码大全
    7/17博客园活动浅谈网站架构中缓存的应用所有资料
    浅谈.NET下的多线程和并行计算(十四)并行计算前言
    公司.NET 3.5培训资料分享
    mongodb分片集群(sharding with replica set)配置
    mongodb有关的研究
  • 原文地址:https://www.cnblogs.com/lyt520/p/15136475.html
Copyright © 2011-2022 走看看