日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

jQuery實(shí)現(xiàn)表格的數(shù)據(jù)拖拽_jquery

作者:喝咖啡還是泡茶 ? 更新時(shí)間: 2022-04-26 編程語(yǔ)言

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

選擇字段
// 拖拽到table

.....

// 從drawer中拖拽數(shù)據(jù)

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讓父組件接收一下

原文鏈接:https://blog.csdn.net/weixin_44328764/article/details/116783360

欄目分類(lèi)
最近更新