sortablejs实现table拖拽

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();

猜你喜欢

转载自blog.csdn.net/m0_37285193/article/details/120316687
今日推荐