zoukankan      html  css  js  c++  java
  • vue+elemenUI实现el-table-column行的上下移动

    最后实现的效果,如图所示,第一行的向上按钮不可操作,最后一行的向下按钮为不可操作。

    其实 vue的很多操作并不是对页面数据的操作,而是对数据源的操作,数据源发生变化,实时渲染页面,这样就达到了,我们的需求。上代码:

    <el-table :key='tableKey' :data="detaillist" border fit highlight-current-row
              style=" 100%">
      <el-table-column align="center" label="序号" width="65">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="股道(号码)" width="145">
        <template slot-scope="scope">
          <span>{{scope.row.bztzdGdhm}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            :disabled="scope.$index===0"
            @click="moveUp(scope.$index,scope.row)"><i class="el-icon-arrow-up"></i></el-button>
          <el-button
            size="mini"
            :disabled="scope.$index===(detaillist.length-1)"
            @click="moveDown(scope.$index,scope.row)"><i class="el-icon-arrow-down"></i></el-button>
          <el-button size="small" type="danger" @click="rowchilddel(scope.$index)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    这是数据的list----------> detaillist: [],
    //向上移动
    moveUp(index, row) {
      var that = this;
      console.log('上移', index, row);
      console.log(that.detaillist[index]);
      if (index > 0) {
        let upDate = that.detaillist[index - 1];
        that.detaillist.splice(index - 1, 1);
        that.detaillist.splice(index, 0, upDate);
      } else {
        alert('已经是第一条,不可上移');
      }
    },
    //向下移动
    moveDown(index, row) {
      var that = this;
      console.log('下移', index, row);
      if ((index + 1) === that.detaillist.length) {
        alert('已经是最后一条,不可下移');
      } else {
        console.log(index);
        let downDate = that.detaillist[index + 1];
        that.detaillist.splice(index + 1, 1);
        that.detaillist.splice(index, 0, downDate);
      }
    },
  • 相关阅读:
    栅栏与自由
    如何种玉米和黄豆
    除了CRUD也要注意IO
    奶糖测试
    看你知道不知道VB6的模块之间循环关系
    [zz]C++类模板
    [zz]C++中std::tr1::function和bind 组件的使用
    [zz]c/c++一些库
    [zz] Python性能鸡汤
    [zz]Linux 下 socket 编程示例
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13300600.html
Copyright © 2011-2022 走看看