add dragdrop for tr

This commit is contained in:
forfire 2018-10-29 14:46:27 +08:00
parent 45f823c0ca
commit 7e8e6ef898
4 changed files with 33 additions and 4 deletions

View file

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<Table border ref="selection" :columns="columns4" :data="data1"></Table> <Table border ref="selection" :columns="columns4" :data="data1" @drag="true" @on-drag-drop="onDragDrop"></Table>
<Button @click="handleSetData">Set Data</Button> <Button @click="handleSetData">Set Data</Button>
<Button @click="handleClearData">Clear Data</Button> <Button @click="handleClearData">Clear Data</Button>
<Button @click="handleSelectAll(true)">Set all selected</Button> <Button @click="handleSelectAll(true)">Set all selected</Button>
@ -69,6 +69,9 @@
}, },
handleClearData () { handleClearData () {
this.data1 = []; this.data1 = [];
},
onDragDrop(a,b){
console.log(a,b)
} }
} }
} }

View file

@ -6,6 +6,7 @@
<tbody :class="[prefixCls + '-tbody']"> <tbody :class="[prefixCls + '-tbody']">
<template v-for="(row, index) in data"> <template v-for="(row, index) in data">
<table-tr <table-tr
:drag="drag"
:row="row" :row="row"
:key="row._rowKey" :key="row._rowKey"
:prefix-cls="prefixCls" :prefix-cls="prefixCls"
@ -58,7 +59,8 @@
fixed: { fixed: {
type: [Boolean, String], type: [Boolean, String],
default: false default: false
} },
drag:Boolean
}, },
computed: { computed: {
expandRender () { expandRender () {

View file

@ -1,11 +1,13 @@
<template> <template>
<tr :class="rowClasses(row._index)"><slot></slot></tr> <tr :class="rowClasses(row._index)" :draggable="drag" v-on:dragstart="onDrag($event,row._index)" v-on:drop="onDrop($event,row._index)" v-on:dragover="allowDrop($event)" v-if="drag" ><slot></slot></tr>
<tr :class="rowClasses(row._index)" v-else ><slot></slot></tr>
</template> </template>
<script> <script>
export default { export default {
props: { props: {
row: Object, row: Object,
prefixCls: String prefixCls: String,
drag:Boolean
}, },
computed: { computed: {
objData () { objData () {
@ -13,6 +15,18 @@
} }
}, },
methods: { methods: {
onDrag(e,index){
e.dataTransfer.setData("index",index);
},
onDrop(e,index){
var dragIndex = e.dataTransfer.getData("index");
this.$parent.$parent.dragAndDrop(dragIndex,index);
e.preventDefault();
},
allowDrop(e)
{
e.preventDefault();
},
rowClasses (_index) { rowClasses (_index) {
return [ return [
`${this.prefixCls}-row`, `${this.prefixCls}-row`,

View file

@ -15,6 +15,7 @@
v-show="!((!!localeNoDataText && (!data || data.length === 0)) || (!!localeNoFilteredDataText && (!rebuildData || rebuildData.length === 0)))"> v-show="!((!!localeNoDataText && (!data || data.length === 0)) || (!!localeNoFilteredDataText && (!rebuildData || rebuildData.length === 0)))">
<table-body <table-body
ref="tbody" ref="tbody"
:drag="drag"
:prefix-cls="prefixCls" :prefix-cls="prefixCls"
:styleObject="tableStyle" :styleObject="tableStyle"
:columns="cloneColumns" :columns="cloneColumns"
@ -50,6 +51,7 @@
<div :class="[prefixCls + '-fixed-body']" :style="fixedBodyStyle" ref="fixedBody"> <div :class="[prefixCls + '-fixed-body']" :style="fixedBodyStyle" ref="fixedBody">
<table-body <table-body
fixed="left" fixed="left"
:drag="drag"
:prefix-cls="prefixCls" :prefix-cls="prefixCls"
:styleObject="fixedTableStyle" :styleObject="fixedTableStyle"
:columns="leftFixedColumns" :columns="leftFixedColumns"
@ -72,6 +74,7 @@
<div :class="[prefixCls + '-fixed-body']" :style="fixedBodyStyle" ref="fixedRightBody"> <div :class="[prefixCls + '-fixed-body']" :style="fixedBodyStyle" ref="fixedRightBody">
<table-body <table-body
fixed="right" fixed="right"
:drag="drag"
:prefix-cls="prefixCls" :prefix-cls="prefixCls"
:styleObject="fixedRightTableStyle" :styleObject="fixedRightTableStyle"
:columns="rightFixedColumns" :columns="rightFixedColumns"
@ -168,6 +171,10 @@
loading: { loading: {
type: Boolean, type: Boolean,
default: false default: false
},
drag:{
type: Boolean,
default: false
} }
}, },
data () { data () {
@ -738,6 +745,9 @@
const data = Csv(columns, datas, params, noHeader); const data = Csv(columns, datas, params, noHeader);
if (params.callback) params.callback(data); if (params.callback) params.callback(data);
else ExportCsv.download(params.filename, data); else ExportCsv.download(params.filename, data);
},
dragAndDrop(a,b) {
this.$emit('on-drag-drop', a,b);
} }
}, },
created () { created () {