jQuery實(shí)現(xiàn)表格的數(shù)據(jù)拖拽
jQuery實(shí)現(xiàn)將一個(gè)ant-table的數(shù)據(jù)拖拽復(fù)制到另一個(gè)ant-table,供大家參考,具體內(nèi)容如下
需求
1、ant-design-vue
2、將一個(gè)嵌套在drawer中的table數(shù)據(jù)拖拽復(fù)制到drawer外面的table中
效果
拖拽中

拖拽后

HTML
<el-button type="text" size="small" class="text-btn" @click="choseField">選擇字段</el-button> // 拖拽到table <a-table class="droptable" :columns="columns_copy" :dataSource="fieldInfoList"> ..... </a-table> // 從drawer中拖拽數(shù)據(jù) <field-select ref="fieldList" @setFieldList="setFieldList"></field-select>
JS
initDrop() {
?? ??? ??? ?// initDrop在mounted中觸發(fā),使table區(qū)域可以接受拖拽?
? ? ? ? ? ? let that = this
? ? ? ? ? ? $('.table_container').droppable({
? ? ? ? ? ? ? ? scope: 'basic', // 設(shè)置兩個(gè)相同的scope接受拖拽信息
? ? ? ? ? ? ? ? tolerance: 'fit',
? ? ? ? ? ? ? ? drop(e) {
? ? ? ? ? ? ? ? ? ? let dropFieldInfo = {
? ? ? ? ? ? ? ? ? ? ? ? enName: that.dragField.enname || '',
? ? ? ? ? ? ? ? ? ? ? ? cnName: that.dragField.name || '',
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? that.fieldInfoList.push(dropFieldInfo)
? ? ? ? ? ? ? ? ? ? that.repeatZhName() // 校驗(yàn)字段是否重復(fù)的方法
? ? ? ? ? ? ? ? }
? ? ? ? ? ? })
? ? ? ? },
?choseField() {
? ? ? ? ? ? this.$refs.fieldList.setShowState(true) ?//顯示drawer
? ? ? ? ? ? // 因?yàn)閐rawer中的dom對(duì)象實(shí)在打開(kāi)抽屜時(shí)候才會(huì)被創(chuàng)建,所以不能再drawer組件中進(jìn)行初始化
? ? ? ? ? ? this.$nextTick(() => {
? ? ? ? ? ? ?? ?// sort-table為抽屜組件中ant-table的類(lèi)名
? ? ? ? ? ? ? ? $('.sort-table tbody tr').draggable({
? ? ? ? ? ? ? ? ? ? scope: 'basic', ?//相同的scope name
? ? ? ? ? ? ? ? ? ? scroll: false,
? ? ? ? ? ? ? ? ? ? zIndex: 10000, ?// zindex設(shè)置更高避免拖拽的數(shù)據(jù)被drawer遮住,同時(shí)去除遮罩層樣式
? ? ? ? ? ? ? ? ? ? helper: 'clone',
? ? ? ? ? ? ? ? ? ? appendTo: 'body', ?//避免遮蓋
? ? ? ? ? ? ? ? ? ? containment: document.getElementById('app'),
? ? ? ? ? ? ? ? ? ? start: e => {
? ? ? ? ? ? ? ? ? ? ?? ?// rowIndex第一行是表頭,數(shù)據(jù)行的rowindex從1開(kāi)始
? ? ? ? ? ? ? ? ? ? ? ? let currentIndex = e.target.rowIndex - 1
? ? ? ? ? ? ? ? ? ? ? ? // console.log(this.$refs.fieldList.tableData[currentIndex])
? ? ? ? ? ? ? ? ? ? ? ? this.dragField = this.$refs.fieldList.tableData[currentIndex]
? ? ? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? ? ? stop: e => {
? ? ? ? ? ? ? ? ? ? ? ? // this.eventType = 'CLICK'
? ? ? ? ? ? ? ? ? ? ? ? console.log('拖拽結(jié)束事件')
? ? ? ? ? ? ? ? ? ? ? ? console.log(e)
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? })
? ? ? ? ? ? })
? },注意事項(xiàng)
1、drop和drag區(qū)域要配置相同的scope
2、為了避免拖拽的helper被遮住,drag要配置zIndex和appendTo
3、如果表格有翻頁(yè)或者查詢(xún)功能,列表數(shù)據(jù)會(huì)刷新,jq的拖拽會(huì)失效,在getList請(qǐng)求方法成功之后,在初始化一次拖拽事件即可,然后使用$emit讓父組件接收一下
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
ASP.NET jQuery 實(shí)例13 原創(chuàng)jQuery文本框字符限制插件-TextArea Counter
這節(jié)介紹一個(gè)自己寫(xiě)的jQuery文本框字符限制插件,至于如何寫(xiě)插件,我這里就不多講了,可以查看相關(guān)介紹,這里主要介紹下該插件的功能2012-02-02
使用jQuery validate 驗(yàn)證注冊(cè)表單實(shí)例演示
Validation是jQuery的插件,提供的方法可以大大簡(jiǎn)化驗(yàn)證表單的工作,接下來(lái)為大家詳細(xì)介紹下使用方法,感興趣的各位可以參考下哈2013-03-03
jQuery無(wú)刷新分頁(yè)完整實(shí)例代碼
這篇文章主要介紹了jQuery無(wú)刷新分頁(yè)實(shí)現(xiàn)方法,以完整實(shí)例形式分析了jQuery實(shí)現(xiàn)分頁(yè)的數(shù)值計(jì)算與元素操作相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10
jQuery實(shí)現(xiàn)可拖動(dòng)進(jìn)度條實(shí)例代碼
這篇文章主要介紹了jQuery實(shí)現(xiàn)可拖動(dòng)進(jìn)度條實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-06-06
JQueryMiniUI按照時(shí)間進(jìn)行查詢(xún)的實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇JQueryMiniUI按照時(shí)間進(jìn)行查詢(xún)的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-06-06
jQuery實(shí)現(xiàn)右下角可縮放大小的層完整實(shí)例
這篇文章主要介紹了jQuery實(shí)現(xiàn)右下角可縮放大小的層,以完整實(shí)例形式分析了jQuery頁(yè)面元素及相關(guān)樣式屬性操作技巧,需要的朋友可以參考下2016-06-06
jQuery中$.ajax()和$.getJson()同步處理詳解
這篇文章主要介紹了jQuery中$.ajax()和$.getJson()同步處理詳解的相關(guān)資料,非常的細(xì)致全面,有需要的小伙伴可以參考下。2015-08-08
仿當(dāng)當(dāng)網(wǎng)淘寶網(wǎng)等主流電子商務(wù)網(wǎng)站商品分類(lèi)導(dǎo)航菜單
本文實(shí)現(xiàn)了一個(gè)分類(lèi)導(dǎo)航的菜單,和大多數(shù)流行的電子商務(wù)網(wǎng)站類(lèi)似,詳細(xì)的實(shí)現(xiàn)可以直接查看源代碼.所有的代碼都在一個(gè)sidebar.html文件中2013-09-09

