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í)在打開抽屜時(shí)候才會(huì)被創(chuàng)建,所以不能再drawer組件中進(jìn)行初始化 ? ? ? ? ? ? this.$nextTick(() => { ? ? ? ? ? ? ?? ?// sort-table為抽屜組件中ant-table的類名 ? ? ? ? ? ? ? ? $('.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開始 ? ? ? ? ? ? ? ? ? ? ? ? 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、如果表格有翻頁或者查詢功能,列表數(shù)據(jù)會(huì)刷新,jq的拖拽會(huì)失效,在getList請(qǐng)求方法成功之后,在初始化一次拖拽事件即可,然后使用$emit讓父組件接收一下
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
ui組件之input多選下拉實(shí)現(xiàn)方法(帶有搜索功能)
這篇文章主要介紹了ui組件之input多選下拉實(shí)現(xiàn)方法(帶有搜索功能)的相關(guān)資料,需要的朋友可以參考下2016-07-07jQuery+CSS3文字跑馬燈特效的簡(jiǎn)單實(shí)現(xiàn)
下面小編就為大家?guī)硪黄猨Query+CSS3文字跑馬燈特效的簡(jiǎn)單實(shí)現(xiàn)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家看,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-06-06jquery+CSS實(shí)現(xiàn)的多級(jí)豎向展開樹形TRee菜單效果
這篇文章主要介紹了jquery+CSS實(shí)現(xiàn)的多級(jí)豎向展開樹形TRee菜單效果,通過jquery自定義函數(shù)設(shè)置相應(yīng)參數(shù)實(shí)現(xiàn)屬性TRee菜單效果的功能,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-08-08jQuery對(duì)象與DOM對(duì)象之間的相互轉(zhuǎn)換
本文主要給大家介紹的是jQuery對(duì)象與DOM對(duì)象之間的相互轉(zhuǎn)換的方法和示例,非常實(shí)用,這里推薦給有需要的小伙伴參考下。2015-03-03使用DataTable插件實(shí)現(xiàn)異步加載數(shù)據(jù)
本文給大家分享的是Jquery+dataTable插件來實(shí)現(xiàn)異步加載數(shù)據(jù)的示例代碼,非常實(shí)用,有需要的小伙伴可以參考下2017-11-11jQuery實(shí)現(xiàn)全選、反選和不選功能的方法詳解
這篇文章主要介紹了jQuery實(shí)現(xiàn)全選、反選和不選功能的方法,結(jié)合實(shí)例形式詳細(xì)分析了jQuery全選、反選以及不選功能的相關(guān)原理、實(shí)現(xiàn)方法及操作注意事項(xiàng),需要的朋友可以參考下2019-12-12jQuery Jcrop插件實(shí)現(xiàn)圖片選取功能
今天我們要在ASP.NET中用jQuery.Jcrop插件實(shí)現(xiàn)圖片的選取功能,你想選取美女的哪個(gè)部位你說了算,我就管不著了2011-11-11jquery input checked全選與反選1.3.2的版本
jquery 全選與反選1.3.2的版本2009-05-05基于JavaScript如何實(shí)現(xiàn)ajax調(diào)用后臺(tái)定義的方法
由于ajax的獨(dú)特優(yōu)勢(shì),使得它在當(dāng)前大量網(wǎng)站得到了廣泛的應(yīng)用,下面就介紹一下ajax如何調(diào)用后臺(tái)定義的函數(shù),對(duì)ajax調(diào)用后臺(tái)方法相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2015-12-12jquery購(gòu)物車實(shí)時(shí)結(jié)算特效實(shí)現(xiàn)思路
購(gòu)物車是可以實(shí)時(shí)結(jié)算,下面為大家解釋下通過jquery是如何實(shí)現(xiàn)的,感興趣的朋友可以了解下2013-09-09