Vue UI Components Documentation
Vue ToolBar Component
The ToolBar component for Vue represents a toolbar where different tools (including widgets) can be automatically added. By default, jqxToolBar supports the widgets Button, ToggleButton, DropDownList, ComboBox and Input but custom tools can also be added.
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 ToolBar component for Vue requires the following import:
import JqxToolbar from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxtoolbar.vue';
Add the jqxToolBar component to the components section of the the Vue class:
components: { JqxToolbar },
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 - <JqxToolBar/>
<template> <JqxToolbar :width="width" :height="height" :tools="tools" :initTools="initTools"> </JqxToolbar></template>
Properties
The properties of the <JqxToolBar/> 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: 500, height: 35, tools: 'toggleButton toggleButton toggleButton | toggleButton | dropdownlist combobox | input | custom' }}
Events
The events in Vue are set as an attribute with @ prefix, for example:
<JqxToolbar @open="onOpen()" :width="width" :height="height" :tools="tools" :initTools="initTools"></JqxToolbar>
All events that are bound to a component are implemented in the methods
member of the Vue class.
methods: { onOpen: 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:
<JqxToolBar ref="toolbar"></JqxToolBar>
Here how you can use a component's method:
this.$refs.toolbar.onOpen();
If we want to add additional methods we should also implement them in the methods
member.
methods: { // Add here all used callbacks and/or events onOpen: function () { // Do something... let tools = this.refs.toolbar.getTools(); alert(tools); }, initTools: function (type, index, tool, menuToolIninitialization) { const icon = document.createElement('div'); if (type == 'toggleButton') { icon.className = 'jqx-editor-toolbar-icon jqx-editor-toolbar-icon-arctic buttonIcon '; } switch (index) { case 0: icon.className += 'jqx-editor-toolbar-icon-bold jqx-editor-toolbar-icon-bold-arctic'; icon.setAttribute('title', 'Bold'); tool[0].appendChild(icon); break; case 1: icon.className += 'jqx-editor-toolbar-icon-italic jqx-editor-toolbar-icon-italic-arctic'; icon.setAttribute('title', 'Italic'); tool[0].appendChild(icon); break; case 2: icon.className += 'jqx-editor-toolbar-icon-underline jqx-editor-toolbar-icon-underline-arctic'; icon.setAttribute('title', 'Underline'); tool[0].appendChild(icon); break; case 3: tool.jqxToggleButton({ width: 80, toggled: true }); tool.text('Enabled'); tool.on('click', () => { const toggled = tool.jqxToggleButton('toggled'); if (toggled) { tool.text('Enabled'); } else { tool.text('Disabled'); } }); break; case 4: tool.jqxDropDownList({ width: 130, source: ["<span style='font-family: Courier New;'>Courier New</span>", "<span style='font-family: Times New Roman;'>Times New Roman</span>", "<span style='font-family: Verdana;'>Verdana</span>"], selectedIndex: 1 }); break; case 5: tool.jqxComboBox({ width: 50, source: [8, 9, 10, 11, 12, 14, 16, 18, 20], selectedIndex: 3 }); break; case 6: tool.jqxInput({ width: 200, placeHolder: 'Type here to search...' }); break; case 7: const button = document.createElement('div'); const img = document.createElement('img'); img.src = 'images/administrator.png' img.title = 'Custom tool'; button.appendChild(img); tool[0].appendChild(button); tool.jqxButton({ height: 15 }); break; } }}
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> <JqxToolbar ref="toolbar" @open="onOpen()" :width="width" :height="height" :tools="tools" :initTools="initTools"> </JqxToolbar></template> <script> // Import the components that will be used import JqxToolbar from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxtoolbar.vue'; export default { components: { // Adding imported widgets here JqxToolbar }, data: function () { // Define properties which will use in the widget return { width: 500, height: 35, tools: 'toggleButton toggleButton toggleButton | toggleButton | dropdownlist combobox | input | custom' } }, beforeCreate: function () { // Add here any data where you want to transform before components be rendered }, methods: { // Add here all used callbacks and/or events onOpen: function () { // Do something... let tools = this.refs.toolbar.getTools(); alert(tools); }, initTools: function (type, index, tool, menuToolIninitialization) { const icon = document.createElement('div'); if (type == 'toggleButton') { icon.className = 'jqx-editor-toolbar-icon jqx-editor-toolbar-icon-arctic buttonIcon '; } switch (index) { case 0: icon.className += 'jqx-editor-toolbar-icon-bold jqx-editor-toolbar-icon-bold-arctic'; icon.setAttribute('title', 'Bold'); tool[0].appendChild(icon); break; case 1: icon.className += 'jqx-editor-toolbar-icon-italic jqx-editor-toolbar-icon-italic-arctic'; icon.setAttribute('title', 'Italic'); tool[0].appendChild(icon); break; case 2: icon.className += 'jqx-editor-toolbar-icon-underline jqx-editor-toolbar-icon-underline-arctic'; icon.setAttribute('title', 'Underline'); tool[0].appendChild(icon); break; case 3: tool.jqxToggleButton({ width: 80, toggled: true }); tool.text('Enabled'); tool.on('click', () => { const toggled = tool.jqxToggleButton('toggled'); if (toggled) { tool.text('Enabled'); } else { tool.text('Disabled'); } }); break; case 4: tool.jqxDropDownList({ width: 130, source: ["<span style='font-family: Courier New;'>Courier New</span>", "<span style='font-family: Times New Roman;'>Times New Roman</span>", "<span style='font-family: Verdana;'>Verdana</span>"], selectedIndex: 1 }); break; case 5: tool.jqxComboBox({ width: 50, source: [8, 9, 10, 11, 12, 14, 16, 18, 20], selectedIndex: 3 }); break; case 6: tool.jqxInput({ width: 200, placeHolder: 'Type here to search...' }); break; case 7: const button = document.createElement('div'); const img = document.createElement('img'); img.src = 'images/administrator.png' img.title = 'Custom tool'; button.appendChild(img); tool[0].appendChild(button); tool.jqxButton({ height: 15 }); break; } } } }</script> <style></style>
ToolBar Example
<template> <div> <JqxToolbar ref="myToolbar" :width="width" :height="35" :tools="tools" :initTools="initTools"> </JqxToolbar> <div style="margin-top: 50px"></div> <JqxButton @click="addToggleBtnOnClick()" :width="150">Add a Toggle Button</JqxButton> <JqxButton @click="addCustomToolBtnOnClick()" :width="150">Add a Custom Tool</JqxButton> <div style="margin-top: 10px; margin-bottom: 2px"> Insert position: </div> <JqxDropDownList ref="myDropDownList" :width="150" :height="22" :source="['first','last']" :selectedIndex="1" :autoDropDownHeight="true"> </JqxDropDownList> <div style="margin-top: 50px"></div> <JqxButton @click="disableToolBtnOnClick()" :width="150">Disable Tool</JqxButton> <JqxButton @click="enableToolBtnOnClick()" :width="150">Enable Tool</JqxButton> <JqxButton @click="destroyToolBtnOnClick()" :width="150">Destroy Tool</JqxButton> <div style="margin-top: 10px; margin-bottom: 2px"> Tool index: </div> <JqxNumberInput ref="myNumberInput" :width="50" :height="25" :decimal="0" :decimalDigits="0" :inputMode="'simple'"> </JqxNumberInput> </div></template> <script> import JqxToolbar from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxtoolbar.vue'; import JqxButton from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxbuttons.vue'; import JqxNumberInput from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxnumberinput.vue'; import JqxDropDownList from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxdropdownlist.vue'; export default { components: { JqxToolbar, JqxButton, JqxNumberInput, JqxDropDownList }, data: function () { return { width: 500, tools: 'toggleButton toggleButton toggleButton | toggleButton | dropdownlist combobox | input', countries: ['Argentina', 'Austria', 'Canada', 'China', 'France', 'Germany', 'Japan', 'Mexico', 'Spain', 'Sweden', 'Switzerland', 'UK', 'USA'] } }, methods: { initTools: function (type, index, tool, menuToolIninitialization) { const icon = document.createElement('div'); if (type == 'toggleButton') { icon.className = 'jqx-editor-toolbar-icon buttonIcon '; } switch (index) { case 0: icon.className += 'jqx-editor-toolbar-icon-bold'; icon.setAttribute('title', 'Bold'); tool[0].appendChild(icon); break; case 1: icon.className += 'jqx-editor-toolbar-icon-italic'; icon.setAttribute('title', 'Italic'); tool[0].appendChild(icon); break; case 2: icon.className += 'jqx-editor-toolbar-icon-underline'; icon.setAttribute('title', 'Underline'); tool[0].appendChild(icon); break; case 3: tool.jqxToggleButton({ width: 80, toggled: true }); tool[0].innerText = 'Enabled'; tool.on('click', () => { let toggled = tool.jqxToggleButton('toggled'); if (toggled) { tool.text('Enabled'); } else { tool.text('Disabled'); } }); break; case 4: tool.jqxDropDownList({ width: 130, source: ['<span style="font-family: Courier New;">Courier New</span>', '<span style="font-family: Times New Roman;">Times New Roman</span>', '<span style="font-family: Verdana;">Verdana</span>'], selectedIndex: 1 }); break; case 5: tool.jqxComboBox({ width: 50, source: [8, 9, 10, 11, 12, 14, 16, 18, 20], selectedIndex: 3 }); break; case 6: tool.jqxInput({ width: 200, placeHolder: 'Type here to search...' }); break; } }, addToggleBtnOnClick: function () { const position = this.$refs.myDropDownList.val(); this.$refs.myToolbar.addTool('toggleButton', position, false, (type, tool, menuToolIninitialization) => { const width = menuToolIninitialization ? '95%' : 50; tool.jqxToggleButton({ width: width, toggled: false }); tool.text('Off'); tool.on('click', () => { const toggled = tool.jqxToggleButton('toggled'); toggled ? tool.text('On') : tool.text('Off'); }); }); }, addCustomToolBtnOnClick: function () { const position = this.$refs.myDropDownList.val(); const country = this.countries[Math.floor(Math.random() * this.countries.length)]; this.$refs.myToolbar.addTool('custom', position, false, (type, tool, menuToolIninitialization) => { tool.append('<img src="images/' + country + '.png" style="float: left; clear: both;" />'); if (menuToolIninitialization) { tool.find('img').css('margin-right', '10px'); tool.find('img').css('margin-top', '4px'); tool.append('<div style="float: left; height: 100%; vertical-align: middle;">' + country + '</div>'); } else { tool.attr('title', 'Flag of ' + country); } }); }, disableToolBtnOnClick: function () { const toolIndex = this.$refs.myNumberInput.val(); this.$refs.myToolbar.disableTool(toolIndex, true); }, enableToolBtnOnClick: function () { const toolIndex = this.$refs.myNumberInput.val(); this.$refs.myToolbar.disableTool(toolIndex, false); }, destroyToolBtnOnClick: function () { const toolIndex = this.$refs.myNumberInput.val(); this.$refs.myToolbar.destroyTool(toolIndex); } } }</script> <style> .jqx-button:not(.jqx-toolbar-tool) { display: inline-block; margin-right: 5px; } .buttonIcon { margin: -5px 0 0 -3px; width: 16px; height: 17px; } .jqx-listbox { z-index: 999999 !important; }</style>