Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] 功能改进建议: 希望el-table支持拖拽排序 #3543

Closed
istobran opened this issue Mar 16, 2017 · 34 comments
Closed

Comments

@istobran
Copy link

http://element.eleme.io/#/zh-CN/component/table
看了官方文档之后发现这个表格是按列实现的
这也导致了el-table没办法直接使用vue.draggable和vue-sortable组件库来进行拖拽排序
希望el-table能够实现行的拖拽排序

@ilvsx
Copy link

ilvsx commented Mar 22, 2017

+1

@ilvsx
Copy link

ilvsx commented Mar 22, 2017

不过目前可以用 https://github.com/RubaXa/Sortable 来做拖拽

import Sortable from 'sortablejs'

let el = document.querySelectorAll('.el-table__body-wrapper > table > tbody')[0]
let sortable = Sortable.create(el)

@SidFeng
Copy link

SidFeng commented Mar 30, 2017

+1 其实只要能让我把属性draggable="true" 加到行上去就可以,目前好像不能单独对行增加属性

@zzzgit
Copy link

zzzgit commented Apr 25, 2017

有些公司会有这个需求,希望加上这个功能

@zzzgit
Copy link

zzzgit commented Apr 25, 2017

https://github.com/RubaXa/Sortable 拖拽之后,数据模型的顺序并不会跟着变,这是个麻烦事

@loca-spirit
Copy link

同求此问题,拖拽列,并且再次的resize,如果只是拖拽还好,但是还需要再次resize,数据模型并没有跟着变,楼上有解决方案吗,还是换了控件?

@yobi-maggie
Copy link

同求此功能

@ark930
Copy link

ark930 commented Aug 10, 2017

同求

@guaizi149
Copy link

同求

@Leopoldthecoder
Copy link
Contributor

提供一个结合 Sortable 的例子:https://jsfiddle.net/gozhg07a/

关于数据模型,其实 Sortable 提供了 onEnd 钩子,上面的例子就是在这个钩子里完成了数据的同步。

@Andyliwr
Copy link

@Leopoldthecoder 通过splice改变了数组(this.products),但是页面上表格行的顺序并未刷新的问题该如何解决呢?

@aweiu
Copy link
Contributor

aweiu commented Jan 25, 2018

@Andyliwr 我目前是调用el-table实例的$destory$mount方法实现重绘的。。
更彻底点可通过v-if实现重绘

@Ray-56
Copy link

Ray-56 commented Mar 22, 2018

@aweiu 我的好像还是不行 你是如何实现的呢

@BlackEyeByLee
Copy link

用sortable.js其实可以做到列拖动或者行拖动

    <el-table border max-height="400" :data="tableData" tooltip-effect="dark" size="mini" @row-dblclick="rowDblClick">
      <el-table-column :type='dataTheadList[index] === "selection" ? "selection" : ""' :prop="dataTheadList[index]" show-overflow-tooltip :label='item' v-for="(item, index) in elTheadList" :key="`thead_${index}`">
      </el-table-column>
    </el-table>
  const el = document.querySelectorAll('.el-table__header-wrapper tr')[0]
  this.sortable = Sortable.create(el, {
    filter: '.el-table-column--selection',
    disabled: true, // 禁用
    animation: 180,
    delay: 0,
    setData: function(dataTransfer) {
      dataTransfer.setData('Text', '')
      // to avoid Firefox bug
      // Detail see : https://github.com/RubaXa/Sortable/issues/1012
    },
    onEnd: evt => {
      // 拖动时sortTable改变了el,
      // 手动转换data
      const oldItem = this.dataTheadList[evt.oldIndex]
      this.dataTheadList.splice(evt.oldIndex, 1)
      this.dataTheadList.splice(evt.newIndex, 0, oldItem)
    }
  })

@Palenew
Copy link

Palenew commented Apr 8, 2018

真的很需要行排序 😂
sortable之前用toArray导出顺序上传,elementUI不方便给tr添加 dataIdAttr ,就没法直接导出了。

@pyuany
Copy link

pyuany commented Apr 25, 2018

+1

@ahDDD
Copy link

ahDDD commented Jun 7, 2018

在el-dialog中使用, 需要加一个setTimeout才能使用? 这是为何
jsfiddle

@zzzgit
Copy link

zzzgit commented Jun 7, 2018

nextTick可以嗎

@appleCXT
Copy link

appleCXT commented Jun 8, 2018

很需要行拖拽,还有跟后台的数据交互灵活些,用sortablejs onMove无法获取拖拽前节点的数据,不是单单获取节点的html

@jocabrera
Copy link

jocabrera commented Jul 23, 2018

How use Sortable.js with Element table columns?

@jocabrera
Copy link

jocabrera commented Jul 23, 2018

Here is an example of how drag-drop columns with Sortable.js

https://jsfiddle.net/gozhg07a/295/

@c4cat
Copy link

c4cat commented Aug 18, 2018

如果发现view无论如何都没有更新, 尝试加上row-key

@BlackHole1
Copy link

+1 很需要这个功能

@Ray-56
Copy link

Ray-56 commented Aug 21, 2018

@jocabrera
not column. how to use row

@jocabrera
Copy link

@guokangf
using drag and drop in the row. https://jsfiddle.net/gozhg07a/416/

@Hanzhuo0322
Copy link

附议

@MohitTilwani15
Copy link

Has anyone tried show and hide columns using checkbox group and also drag and drop. the checkbox group has different checkboxes based on number of columns and toggling checkboxes will show/hide the column and also drag and drop works fine with it?

@liub1934
Copy link
Contributor

表格数据没有重绘的加个row-key就行了,row-key和ID一样需要设置唯一的一个字段名

@csvwolf csvwolf closed this as completed Nov 2, 2018
@Ray-56
Copy link

Ray-56 commented Nov 2, 2018

@liub1934 That's true!! use sortable.js

@Lara-gru
Copy link

Lara-gru commented Feb 1, 2019

Try this https://github.com/WakuwakuP/element-ui-el-table-draggable for el-tabel - drag-n-drop row

@zymchan
Copy link

zymchan commented Feb 19, 2019

提供一个结合 Sortable 的例子:https://jsfiddle.net/gozhg07a/

关于数据模型,其实 Sortable 提供了 onEnd 钩子,上面的例子就是在这个钩子里完成了数据的同步。

这里你使用了钩子 但是还是需要绑定唯一的row-key。能不能不绑定row-key?

@Elm1992
Copy link

Elm1992 commented Jan 16, 2020

Here is an example of how drag-drop columns with Sortable.js

https://jsfiddle.net/gozhg07a/295/
@jocabrera

hi bro, using drag and drop in the columns,The table will flash.
Look forward to your favourable reply.
demo: https://codepen.io/xxlion/pen/abzjKMg

@sunmaolin
Copy link

树形表格拖拽排序真的很费脑,看来官方是不考虑这个功能了

@freemedom
Copy link

freemedom commented Sep 12, 2023

我在el-table上使用clone,但是每次clone都会在原table中加入clone出来的el-table无法控制的一行,更新数据后table中仍会保留clone的这一行。(row-key不管用)解决办法是

我目前是调用el-table实例的$destory和$mount方法实现重绘的。。
更彻底点可通过v-if实现重绘

不过我没理解$mount是怎么用的,我是用的v-if @aweiu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests