Vue UI Components Documentation
Vue Tree Component
The Tree component for Vue represents a Tree widget that displays a hierarchical collection of items. You can populate it from 'UL' or by using its 'source' property.
Prerequisites
Refer to Vue Getting Started before you start with this help topic.
Configuration
After you have created your App.vue file, here is how you should structure it:
The Tree component for Vue requires the following import:
import JqxTree from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxtree.vue';
Add the jqxTree component to the components section of the the Vue class:
components: { JqxTree },
Template
The App.vue has a <template>
structural tag where we determine the application structure.
There we will also set the tags for the new components - <JqxTree/>
<template> <JqxTree :width="width" :height="height" :source="treeSource"> </JqxTree></template>
Properties
The properties of the <JqxTree/> component are defined in the data
member of the Vue class.
We should put them in the return object of the data function:
data: function () { return { width: 200, height: 600, treeSource: [ { icon: 'images/mailIcon.png', label: 'Mail', expanded: true, items: [ { icon: 'images/calendarIcon.png', label: 'Calendar' }, { icon: 'images/contactsIcon.png', label: 'Contacts', selected: true } ] }, { icon: 'images/folder.png', label: 'Inbox', expanded: true, items: [ { icon: 'images/folder.png', label: 'Admin' }, { icon: 'images/folder.png', label: 'Corporate' }, { icon: 'images/folder.png', label: 'Finance' }, { icon: 'images/folder.png', label: 'Other' }, ] }, { icon: 'images/recycle.png', label: 'Deleted Items' }, { icon: 'images/notesIcon.png', label: 'Notes' }, { icon: 'images/settings.png', label: 'Settings', iconsize: 14 }, { icon: 'images/favorites.png', label: 'Favorites' } ] }}
Events
The events in Vue are set as an attribute with @ prefix, for example:
<JqxTree @select="onSelect()" :width="width" :height="height" :source="treeSource"></JqxTree>
All events that are bound to a component are implemented in the methods
member of the Vue class.
methods: { onSelect: function () { // Do something... }}
Methods
To use a component's method we should have its reference. In Vue we refer to a component by the special $refs
property.
Before that we need to add the desired name reference to that component:
<JqxTree ref="tree"></JqxTree>
Here how you can use a component's method:
this.$refs.tree.refresh();
If we want to add additional methods we should also implement them in the methods
member.
In case we need to do some precalculation or something else before the components are rendered, we should use the beforeCreate
member.
It depends on the case.
If you have followed the above steps, you App.vue file would look like this:
App.vue:
<template> <JqxTree ref="tree" @select="onSelect()" :width="width" :height="height" :source="treeSource"> </JqxTree></template> <script> // Import the components that will be used import JqxTree from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxtree.vue'; export default { components: { // Adding imported widgets here JqxTree }, data: function () { // Define properties which will use in the widget return { width: 200, height: 600, treeSource: [ { icon: 'images/mailIcon.png', label: 'Mail', expanded: true, items: [ { icon: 'images/calendarIcon.png', label: 'Calendar' }, { icon: 'images/contactsIcon.png', label: 'Contacts', selected: true } ] }, { icon: 'images/folder.png', label: 'Inbox', expanded: true, items: [ { icon: 'images/folder.png', label: 'Admin' }, { icon: 'images/folder.png', label: 'Corporate' }, { icon: 'images/folder.png', label: 'Finance' }, { icon: 'images/folder.png', label: 'Other' }, ] }, { icon: 'images/recycle.png', label: 'Deleted Items' }, { icon: 'images/notesIcon.png', label: 'Notes' }, { icon: 'images/settings.png', label: 'Settings', iconsize: 14 }, { icon: 'images/favorites.png', label: 'Favorites' } ] } }, beforeCreate: function () { // Add here any data where you want to transform before components be rendered }, methods: { // Add here all used callbacks and/or events onSelect: function () { // Do something... let selected = this.refs.tree.getSelectedItem(); alert(selected); } } }</script> <style></style>
Tree Example
<template> <div> <JqxTree ref="myTree" style="float: left" :width="300" :height="450"> <ul> <li id="home">Home</li> <li id="solutions"> Solutions <ul> <li>Education</li> <li>Financial services</li> <li>Government</li> <li>Manufacturing</li> <li> Solutions <ul> <li>Consumer photo and video</li> <li>Mobile</li> <li>Rich Internet applications</li> <li>Technical communication</li> <li>Training and eLearning</li> <li>Web conferencing</li> </ul> </li> <li>All industries and solutions</li> </ul> </li> <li> Products <ul> <li>PC products</li> <li>Mobile products</li> <li>All products</li> </ul> </li> <li> Support <ul> <li>Support home</li> <li>Customer Service</li> <li>Knowledge base</li> <li>Books</li> <li>Training and certification</li> <li>Support programs</li> <li>Forums</li> <li>Documentation</li> <li>Updates</li> </ul> </li> <li> Communities <ul> <li>Designers</li> <li>Developers</li> <li>Educators and students</li> <li>Partners</li> <li> By resource <ul> <li>Labs</li> <li>TV</li> <li>Forums</li> <li>Exchange</li> <li>Blogs</li> <li>Experience Design</li> </ul> </li> </ul> </li> <li> Company <ul> <li>About Us</li> <li>Press</li> <li>Investor Relations</li> <li>Corporate Affairs</li> <li>Careers</li> <li>Showcase</li> <li>Events</li> <li>Contact Us</li> <li>Become an affiliate</li> </ul> </li> </ul> </JqxTree> <div style="margin-left: 60px; float: left"> <div style="margin-top: 10px"> <JqxButton @click="AddOnClick()" :width="125" :height="25">Add</JqxButton> </div> <div style="margin-top: 10px"> <JqxButton @click="AddAfterOnClick()" :width="125" :height="25">Add After</JqxButton> </div> <div style="margin-top: 10px"> <JqxButton @click="AddBeforeOnClick()" :width="125" :height="25">Add Before</JqxButton> </div> <div style="margin-top: 10px"> <JqxButton @click="UpdateOnClick()" :width="125" :height="25">Update</JqxButton> </div> <div style="margin-top: 10px"> <JqxButton @click="RemoveOnClick()" :width="125" :height="25">Remove</JqxButton> </div> <div style="margin-top: 10px"> <JqxButton @click="DisableOnClick()" :width="125" :height="25">Disable</JqxButton> </div> <div style="margin-top: 10px"> <JqxButton @click="ExpandOnClick()" :width="125" :height="25">Expand</JqxButton> </div> <div style="margin-top: 10px"> <JqxButton @click="CollapseOnClick()" :width="125" :height="25">Collapse</JqxButton> </div> <div style="margin-top: 10px"> <JqxButton @click="ExpandAllOnClick()" :width="125" :height="25">Expand All</JqxButton> </div> <div style="margin-top: 10px"> <JqxButton @click="CollapseAllOnClick()" :width="125" :height="25">Collapse All</JqxButton> </div> <div style="margin-top: 10px"> <JqxButton @click="EnableAllOnClick()" :width="125" :height="25">Enable All</JqxButton> </div> <div style="margin-top: 10px"> <JqxButton @click="NextOnClick()" :width="125" :height="25">Next Item</JqxButton> </div> <div style="margin-top: 10px"> <JqxButton @click="PreviousOnClick()" :width="125" :height="25">Previous Item</JqxButton> </div> </div> </div></template> <script> import JqxTree from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxtree.vue'; import JqxButton from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxbuttons.vue'; export default { components: { JqxTree, JqxButton }, mounted: function () { this.$refs.myTree.selectItem(document.querySelector('#home')); this.$refs.myTree.expandItem(document.querySelector('#solutions')); }, methods: { AddOnClick: function () { const selectedItem = this.$refs.myTree.getSelectedItem(); if (selectedItem != null) { this.$refs.myTree.addTo({ label: 'Item' }, selectedItem.element); this.$refs.myTree.render(); } else { this.$refs.myTree.addTo({ label: 'Item' }, null); this.$refs.myTree.render(); } }, AddAfterOnClick: function () { const selectedItem = this.$refs.myTree.getSelectedItem(); if (selectedItem != null) { this.$refs.myTree.addAfter({ label: 'Item' }, selectedItem.element); this.$refs.myTree.render(); } }, AddBeforeOnClick: function () { const selectedItem = this.$refs.myTree.getSelectedItem(); if (selectedItem != null) { this.$refs.myTree.addBefore({ label: 'Item' }, selectedItem.element); this.$refs.myTree.render(); } }, UpdateOnClick: function () { const selectedItem = this.$refs.myTree.getSelectedItem(); if (selectedItem != null) { this.$refs.myTree.updateItem({ label: 'Item' }, selectedItem.element); this.$refs.myTree.render(); } }, RemoveOnClick: function () { const selectedItem = this.$refs.myTree.getSelectedItem(); if (selectedItem != null) { this.$refs.myTree.removeItem(selectedItem.element); this.$refs.myTree.render(); } }, DisableOnClick: function () { const selectedItem = this.$refs.myTree.getSelectedItem(); if (selectedItem != null) { this.$refs.myTree.disableItem(selectedItem.element); } }, ExpandOnClick: function () { const selectedItem = this.$refs.myTree.getSelectedItem(); if (selectedItem != null) { this.$refs.myTree.expandItem(selectedItem.element); } }, CollapseOnClick: function () { const selectedItem = this.$refs.myTree.getSelectedItem(); if (selectedItem != null) { this.$refs.myTree.collapseItem(selectedItem.element); } }, ExpandAllOnClick: function () { this.$refs.myTree.expandAll(); }, CollapseAllOnClick: function () { this.$refs.myTree.collapseAll(); }, EnableAllOnClick: function () { this.$refs.myTree.enableAll(); }, NextOnClick: function () { const selectedItem = this.$refs.myTree.getSelectedItem(); const nextItem = selectedItem.element.nextElementSibling; if (nextItem != null) { this.$refs.myTree.selectItem(nextItem); this.$refs.myTree.ensureVisible(nextItem); } }, PreviousOnClick: function () { const selectedItem = this.$refs.myTree.getSelectedItem(); const prevItem = selectedItem.element.previousElementSibling; if (prevItem != null) { this.$refs.myTree.selectItem(prevItem); this.$refs.myTree.ensureVisible(prevItem); } } } }</script>