dragging a table column for column sorting with drag implementation
Here are the main methods to use
1.dragstart Drag to start returning to target object
objects passed during the 2.dragenter drag
3.dragend Drag End returns the target object
Section Code *****************************************************************
HTML<table class= "el-table el-table--border el-table--small" style= "margin-top:20px;" ><thead class= "El-table__header-wrapper has-gutter" ><tr><th v-for= "(columns, index) in Tablescolumns "draggable= ' true ' @dragstart =" dragstartevent (index) "@dragenter =" dragenterevent ($event, columns) "@ Dragend= "Dragendevent ($event, Columns)" ><label class= "cell" v-html= "Renderheader (Index, columns)" ></ Label></th></tr></thead><tbody class= "El-table__body" ><tr v-for= "(item, index) in Tables "><TD v-for=" columns in Tablescolumns ">{{item[columns.key]}}</td></tr></tbody> </table>
JS
Datatables:[{bill_type:1 bill_type_name:"Normal storage" ID: owner_id:1 owner_name:"Schwann" receipt_sn:"2018060282" status:4 status_name:"End of Test" }],tablescolumns: [{column:"Document Type" key:"Bill_type_name" type:"checkbox" },{column:"Inbound number" key:"receipt_sn" type:"input" },{column:"Document Status" key:"Status_name" type:"Radio" }],dragendcolumn: {},//destination object last placed Dragstartindex: ""//target Object original index
//table headerRenderheader (index, column) {if (' Renderheader ' in This.tablescolumns[index]) {return this.tablescolumns[index]. Renderheader (column, index);} else {return Column.column | | }},//Drag to start---Record the index of the target object to determine whether to drag forward or backward Dragstartevent (index) {this.dragstartindex = index},// Drag the process---each move an object will go into this method, only the last time to enter this method is the position of the drag end dragenterevent (ev, col) {this.dragendcolumn = col},//drag End--- Delete the target object from the original array and add the target object dragendevent (EV, col) {if (Col.key! = This.dragEndColumn.key) {This.tablesColumns.forEach ( Item, Index) = {if (Item.key = = Col.key) {this.tablesColumns.splice (index, 1)}}) This.tablesColumns.forEach (EL, Index) = = {if (El.key = = This.dragEndColumn.key) {//var data = Deepcopy (This.columns[this.dragstartindex]) var Indexco L = "" if (This.dragstartindex < index) {indexcol = index + 1} else {indexcol = Index}this.tablescolumns.splice (indexcol , 0, col) this.dragendcolumn = {}this.dragstartindex = "" Return}}}}}
Vue drag dragging and sorting columns in a table