Created
September 30, 2018 18:25
-
-
Save davay42/42b134d895f83554e33ffe42518688be to your computer and use it in GitHub Desktop.
vue-draggable-nested-tree demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app | |
.row | |
.col-3 | |
.mb-2 | |
button.btn.btn-primary(@click="collapseAll") collapse all | |
button.btn.btn-primary.ml-1(@click="expandAll") expand all | |
Tree(:data="tree1data" draggable cross-tree) | |
div(slot-scope="{data, store}") | |
template(v-if="!data.isDragPlaceHolder") | |
b(v-if="data.children && data.children.length" @click="store.toggleOpen(data)") {{data.open ? '-' : '+'}} | |
span {{data.text}} | |
.col-3 | |
Tree(:data="tree2data" draggable cross-tree) | |
div(slot-scope="{data, store}") | |
template(v-if="!data.isDragPlaceHolder") | |
b(v-if="data.children && data.children.length" @click="store.toggleOpen(data)") {{data.open ? '-' : '+'}} | |
span {{data.text}} | |
.mt-2 | |
button.btn.btn-primary(@click="addChild") Add child | |
.col-3 | |
Tree.tree3(:data="tree3data" draggable cross-tree) | |
div(slot-scope="{data, store}") | |
template(v-if="!data.isDragPlaceHolder") | |
b(v-if="data.children && data.children.length" @click="store.toggleOpen(data)") {{data.open ? '-' : '+'}} | |
span {{data.text}} | |
.col-3 | |
Tree.tree4(:data="tree4data" draggable cross-tree :indent="30" :space="0") | |
div(slot-scope="{data, store}") | |
template(v-if="!data.isDragPlaceHolder") | |
b(v-if="data.children && data.children.length" @click="store.toggleOpen(data)") {{data.open ? '-' : '+'}} | |
span {{data.text}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
th = treeHelper | |
app = new Vue({ | |
el: '#app', | |
components: {Tree: vueDraggableNestedTree.DraggableTree}, | |
data: { | |
tree1data: [ | |
{text: 'node 1'}, | |
{text: 'node 2'}, | |
{text: 'node 3 undraggable', draggable: false}, | |
{text: 'node 4'}, | |
{text: 'node 4 undroppable', droppable: false}, | |
{text: 'node 5', children: [ | |
{text: 'node 1'}, | |
{text: 'node 2', children: [ | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
]}, | |
{text: 'node 2 undroppable', droppable: false, children: [ | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
]}, | |
{text: 'node 2', children: [ | |
{text: 'node 3'}, | |
{text: 'node 4 undroppable', droppable: false}, | |
]}, | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
]}, | |
], | |
tree2data: [ | |
{text: 'node 1'}, | |
{text: 'node 2'}, | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
], | |
tree3data: [ | |
{text: 'node 1'}, | |
{text: 'node 2'}, | |
{text: 'node 3 undraggable', draggable: false}, | |
{text: 'node 4'}, | |
{text: 'node 4 undroppable', droppable: false}, | |
{text: 'node 5', children: [ | |
{text: 'node 1'}, | |
{text: 'node 2', children: [ | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
]}, | |
{text: 'node 2 undroppable', droppable: false, children: [ | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
]}, | |
{text: 'node 2', children: [ | |
{text: 'node 3'}, | |
{text: 'node 4 undroppable', droppable: false}, | |
]}, | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
]}, | |
], | |
tree4data: [ | |
{text: 'node 1'}, | |
{text: 'node 2'}, | |
{text: 'node 3 undraggable', draggable: false}, | |
{text: 'node 4'}, | |
{text: 'node 4 undroppable', droppable: false}, | |
{text: 'node 5', children: [ | |
{text: 'node 1'}, | |
{text: 'node 2', children: [ | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
]}, | |
{text: 'node 2 undroppable', droppable: false, children: [ | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
]}, | |
{text: 'node 2', children: [ | |
{text: 'node 3'}, | |
{text: 'node 4 undroppable', droppable: false}, | |
]}, | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
{text: 'node 3'}, | |
{text: 'node 4'}, | |
]}, | |
], | |
}, | |
methods: { | |
// add child to tree2 | |
addChild() { | |
this.tree2data[0].children.push({text: 'child'}) | |
}, | |
expandAll() { | |
th.breadthFirstSearch(this.tree1data, node => { | |
node.open = true | |
}) | |
}, | |
collapseAll() { | |
th.breadthFirstSearch(this.tree1data, node => { | |
node.open = false | |
}) | |
}, | |
}, | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17-beta.0/vue.js"></script> | |
<script src="https://unpkg.com/vue-draggable-nested-tree@latest/dist/vue-draggable-nested-tree.js"></script> | |
<script src="https://unpkg.com/tree-helper@latest/dist/tree-helper.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app { | |
padding: 50px; | |
} | |
.he-tree{ | |
border: 1px solid #ccc; | |
padding: 20px; | |
} | |
.tree-node{ | |
} | |
.tree-node-inner{ | |
padding: 5px; | |
border: 1px solid #ccc; | |
cursor: pointer; | |
} | |
.draggable-placeholder{ | |
} | |
.draggable-placeholder-inner{ | |
border: 1px dashed #0088F8; | |
box-sizing: border-box; | |
background: rgba(0, 136, 249, 0.09); | |
color: #0088f9; | |
text-align: center; | |
padding: 0; | |
display: flex; | |
align-items: center; | |
} | |
.tree3{ | |
.tree-node-inner{ | |
border: none; | |
padding: 0px; | |
} | |
.tree-node-inner-back:hover{ | |
background: #ddd; | |
} | |
} | |
.tree4{ | |
.tree-node-inner{ | |
border: none; | |
border-bottom: 1px solid #ccc; | |
padding: 5px 10px; | |
backgroud: #ccc; | |
} | |
.draggable-placeholder-inner{ | |
background-color: orangered; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.0/css/bootstrap.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment