列表排序按钮常用方法,实现“向前移动到第一个↑”、“向前移动∧”、“向后移动∨”、“向后移动到最后一个↓”

<el-button
title="向前移动到第一个"
size="mini"
type="primary"
icon="el-icon-top"
:disabled="tableData.length scope.row.value === tableData[0].value :true"
@click.stop="moveToFirst(scope.row)"
circle
plain/>

<el-button
title="向前移动"
size="mini"
type="primary"
icon="el-icon-arrow-up"
:disabled="tableData.length scope.row.value === tableData[0].value :true"
@click.stop="moveToPrev(scope.row)"
circle
plain/>

<el-button
title="向后移动"
size="mini"
type="primary"
icon="el-icon-arrow-down"
:disabled="tableData.length scope.row.value === tableData.slice(-1)[0].value :true"
@click.stop="moveToNext(scope.row)"
circle
plain/>


<el-button
title="向后移动到最后一个"
size="mini"
type="primary"
icon="el-icon-bottom"
:disabled="tableData.length scope.row.value === tableData.slice(-1)[0].value :true"
@click.stop="moveToLast(scope.row)"
circle
plain/>

方法

getIndex(d) {
    return this.tableData.findIndex(v => v.value == d.value);
},
moveToFirst(d) {
    let idx = this.getIndex(d);
    this.tableData.splice(0, 0, this.tableData.splice(idx, 1)[0]);
},
moveToPrev(d) {
    let idx = this.getIndex(d);
    this.tableData.splice(idx - 1, 0, this.tableData.splice(idx, 1)[0]);
},
moveToNext(d) {
    let idx = this.getIndex(d);
    this.tableData.splice(idx + 1 > this.tableData.length - 1 ? 0 : idx + 1, 0, this.tableData.splice(idx, 1)[0]);
},
moveToLast(d) {
    let idx = this.getIndex(d);
    this.tableData.splice(this.tableData.length - 1, 0, this.tableData.splice(idx, 1)[0]);
},

扩展阅读类比置顶排序排序置顶、非置顶算法,实现置顶后的结果和非置顶的内容排序保持原始序列_你挚爱的强哥的博客-CSDN博客【代码】排序置顶、非置顶算法,实现置顶后的结果和非置顶的内容排序保持原始序列。https://blog.csdn.net/qq_37860634/article/details/131977941

用dragstart、drag、dragend、dragover、drop、dragleave实现针对表格列的顺序进行拖拽排序(附带实现选择某几列数据显示或隐藏)_dragstarte-CSDN博客文章浏览阅读482次,点赞8次,收藏7次。将数组指定索引位置的元素 移动到 目标索引位置,且不改变其他元素原本的顺序,注意这个不是对调元素位置,是移动某一个元素位置不影响其他元素顺(使用场景:拖拽改变数据的顺序,点击上下左右箭头移动元素顺序)-CSDN博客。【代码】将数组指定索引位置的元素 移动到 目标索引位置(使用场景:拖拽改变数据的顺序,点击上下左右箭头移动元素顺序)_dragstartehttps://blog.csdn.net/qq_37860634/article/details/136788464

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值