0
点赞
收藏
分享

微信扫一扫

sortablejs实现table拖拽

践行数据分析 2022-01-30 阅读 55


1.安装sortablejs

npm install sortablejs --save-dev
-或
yarn add sortable -D

2.调用

const tbody = document.querySelector('.ant-table-tbody');
const _this = this;
this.sort = Sortable.create(tbody, {
filter: '.filtered', // 'filtered' class is not draggable
onMove(evt) {//如果被替换对象包括 class:filtered 则不被替换
return !([...evt.related.classList].includes('filtered'));
},
onEnd({ newIndex, oldIndex }) {
const currRow = _this.listData.splice(oldIndex, 1)[0];
_this.listData.splice(newIndex, 0, currRow);
},
});

3.销毁

this.sort.destroy();



举报

相关推荐

0 条评论