Vue UI Components Documentation
Vue ComboBox Component
The ComboBox component for Vue contains an input field with auto-complete functionality and a list of selectable items displayed in a drop-down.
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 ComboBox component for Vue requires the following import:
import JqxComboBox from "jqwidgets-scripts/jqwidgets-vue/vue_jqxcombobox.vue";
Add the jqxComboBox component to the components section of the the Vue class:
components: { JqxComboBox },
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 - <JqxComboBox/>
<template> <JqxComboBox :width="300" :height="25" :source="source" :selectedIndex="0"> </JqxComboBox></template>
Properties
The properties of the <JqxComboBox/> 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 { source: [ // Business & Investing { html: '<div tabIndex=0 style="padding: 1px;"><div>Title: Do the Work</div><div>Author: Steven Pressfield</div></div>', label: 'Do the Work', group: 'Business & Investing' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>Title: Think and Grow Rich</div><div>Author: Napoleon Hill</div></div>', label: 'Think and Grow Rich', group: 'Business & Investing' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>Title: The Toyota Way to Continuous...</div><div>Author: Jeffrey K. Liker</div></div>', label: 'The Toyota Way to Continuous...', group: 'Business & Investing' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>Title: Redesigning Leadership </div><div>Author: John Maeda</div></div>', label: 'Redesigning Leadership ', group: 'Business & Investing' }, // Computer & Internet Books { html: '<div tabIndex=0 style="padding: 1px;"><div>Title: MacBook Pro Portable Genius</div><div>Author: Brad Miser</div></div>', label: 'MacBook Pro Portable Genius', group: 'Computer & Internet Books' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>Title: Social Media Metrics Secrets</div><div>Author: John Lovett</div></div>', label: 'Social Media Metrics Secrets', group: 'Computer & Internet Books' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>Title: iPad 2: The Missing Manual</div><div>Author: J D Biersdorfer J.D</div></div>', label: 'iPad 2: The Missing Manual', group: 'Computer & Internet Books' }, // History { html: '<div tabIndex=0 style="padding: 1px;"><div>Lincoln and His Admirals</div><div>Author:Craig L. Symonds</div></div>', label: 'Lincoln and His Admirals', group: 'History' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>The Dogs of War: 1861</div><div>Author:Emory M. Thomas</div></div>', label: 'The Dogs of War: 1861', group: 'History' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>Cleopatra: A Life</div><div>Author:Stacy Schiff</div></div>', label: 'Cleopatra: A Life', group: 'History' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>Mother Teresa: A Biography</div><div>Author:Meg Greene</div></div>', label: 'Mother Teresa: A Biography', group: 'History' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>The Federalist Papers</div><div>Author:John Jay</div></div>', label: 'The Federalist Papers', group: 'History' }, ] }}
Events
The events in Vue are set as an attribute with @ prefix, for example:
<JqxComboBox @change="onChange()" :width="300" :height="25" :source="source" :selectedIndex="0"></JqxComboBox>
All events that are bound to a component are implemented in the methods
member of the Vue class.
methods: { onChange: 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:
<JqxComboBox ref="combobox"></JqxComboBox>
Here how you can use a component's method:
this.$refs.combobox.close();
methods: { // Add here all used callbacks and/or events onChange: function () { // Do something on change this.$refs.combobox.close(); }}
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> <JqxComboBox ref="combobox" @change="onChange()" :width="300" :height="25" :source="source" :selectedIndex="0"> </JqxComboBox></template> <script> // Import the components that will be used import JqxComboBox from "jqwidgets-scripts/jqwidgets-vue/vue_jqxcombobox.vue"; export default { components: { // Adding imported widgets here JqxComboBox }, data: function () { // Define properties which will use in the widget return { source: [ // Business & Investing { html: '<div tabIndex=0 style="padding: 1px;"><div>Title: Do the Work</div><div>Author: Steven Pressfield</div></div>', label: 'Do the Work', group: 'Business & Investing' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>Title: Think and Grow Rich</div><div>Author: Napoleon Hill</div></div>', label: 'Think and Grow Rich', group: 'Business & Investing' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>Title: The Toyota Way to Continuous...</div><div>Author: Jeffrey K. Liker</div></div>', label: 'The Toyota Way to Continuous...', group: 'Business & Investing' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>Title: Redesigning Leadership </div><div>Author: John Maeda</div></div>', label: 'Redesigning Leadership ', group: 'Business & Investing' }, // Computer & Internet Books { html: '<div tabIndex=0 style="padding: 1px;"><div>Title: MacBook Pro Portable Genius</div><div>Author: Brad Miser</div></div>', label: 'MacBook Pro Portable Genius', group: 'Computer & Internet Books' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>Title: Social Media Metrics Secrets</div><div>Author: John Lovett</div></div>', label: 'Social Media Metrics Secrets', group: 'Computer & Internet Books' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>Title: iPad 2: The Missing Manual</div><div>Author: J D Biersdorfer J.D</div></div>', label: 'iPad 2: The Missing Manual', group: 'Computer & Internet Books' }, // History { html: '<div tabIndex=0 style="padding: 1px;"><div>Lincoln and His Admirals</div><div>Author:Craig L. Symonds</div></div>', label: 'Lincoln and His Admirals', group: 'History' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>The Dogs of War: 1861</div><div>Author:Emory M. Thomas</div></div>', label: 'The Dogs of War: 1861', group: 'History' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>Cleopatra: A Life</div><div>Author:Stacy Schiff</div></div>', label: 'Cleopatra: A Life', group: 'History' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>Mother Teresa: A Biography</div><div>Author:Meg Greene</div></div>', label: 'Mother Teresa: A Biography', group: 'History' }, { html: '<div tabIndex=0 style="padding: 1px;"><div>The Federalist Papers</div><div>Author:John Jay</div></div>', label: 'The Federalist Papers', group: 'History' }, ] } }, beforeCreate: function () { // Add here any data where you want to transform before components be rendered }, methods: { // Add here all used callbacks and/or events onChange: function () { // Do something on change this.$refs.combobox.close(); } } }</script> <style></style>
ComboBox Example
<template> <div> <JqxComboBox @select="myComboBoxOnSelect($event)" :width="150" :height="25" :source="dataAdapter" :selectedIndex="0" :displayMember="'ContactName'" :valueMember="'CompanyName'"> </JqxComboBox> <div ref="selectionlog" style="font-size: 12px; font-family: Verdana"></div> </div></template> <script> import JqxComboBox from "jqwidgets-scripts/jqwidgets-vue/vue_jqxcombobox.vue"; export default { components: { JqxComboBox }, data: function () { return { dataAdapter: new jqx.dataAdapter(this.source) } }, beforeCreate: function () { this.source = { datatype: 'json', datafields: [ { name: 'CompanyName' }, { name: 'ContactName' } ], id: 'id', url: 'sampledata/customers.txt' }; }, methods: { myComboBoxOnSelect: function (event) { if (event.args) { let item = event.args.item; if (item) { let valueElement = document.createElement('div'); valueElement.innerHTML = 'Value: ' + item.value; let labelElement = document.createElement('div'); labelElement.innerHTML = 'Label: ' + item.label; let selectionLog = this.$refs.selectionlog; selectionLog.innerHTML = ''; selectionLog.appendChild(labelElement); selectionLog.appendChild(valueElement); } } } } };</script> <style></style>