Vue drag dragging and sorting columns in a table

Source: Internet
Author: User

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 "&GT;&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.