Vue UI Components Documentation
Vue ButtonGroup Component
The ButtonGroup component for Vue represents a set of buttons that can work as normal buttons, radio buttons or checkboxes.
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 ButtonGroup component for Vue requires the following import:
Add the jqxButtonGroup component to the components section of the the Vue class:
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 - <JqxButtonGroup/>
<template> <JqxButtonGroup :mode="mode"> <button style="padding: 4px 16px" id='Left' value='Left'></button> <button style="padding: 4px 16px" id='Center' value='Center'></button> <button style="padding: 4px 16px" id='Right' value='Right'></button> </JqxButtonGroup></template>
Properties
The properties of the <JqxButtonGroup/> 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 { mode: 'default' }}
Events
The events in Vue are set as an attribute with @ prefix, for example:
<JqxButtonGroup @buttonClick="groupOnBtnClick($event)"> <button style="padding: 4px 16px" id='Left' value='Left'></button> <button style="padding: 4px 16px" id='Center' value='Center'></button> <button style="padding: 4px 16px" id='Right' value='Right'></button></JqxButtonGroup>
All events that are bound to a component are implemented in the methods
member of the Vue class.
methods: { groupOnBtnClick: function (event) { // 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:
<JqxButtonGroup ref="buttongroup"></JqxButtonGroup>
Here how you can use a component's method:
this.$refs.buttongroup.disable();
methods: { // Add here all used callbacks and/or events groupOnBtnClick: function (event) { // Do something when clicking on a button this.$refs.buttongroup.disable(); }}
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:
ButtonGroup Examples
<template> <div> <JqxButtonGroup ref="myButtonGroup" @buttonclick="groupOnBtnClick($event)"> <button style="padding: 4px 16px" id='Left' value='Left'></button> <button style="padding: 4px 16px" id='Center' value='Center'></button> <button style="padding: 4px 16px" id='Right' value='Right'></button> </JqxButtonGroup> <div style="margin-top: 10px"> <h4>Modes</h4> <JqxRadioButton @checked="myDefaultModeButtonChecked()" :checked="true">Default</JqxRadioButton> <JqxRadioButton @checked="myRadioModeButtonChecked()">RadioButtons</JqxRadioButton> <JqxRadioButton @checked="myCheckBoxModeButtonChecked()">CheckBoxes</JqxRadioButton> </div> <div ref="myLog" style="margin-top: 10px;"></div> </div></template> <script> import JqxButtonGroup from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxbuttongroup.vue'; import JqxRadioButton from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxradiobutton.vue'; export default { components: { JqxButtonGroup, JqxRadioButton }, methods: { myDefaultModeButtonChecked: function () { this.$refs.myButtonGroup.mode = 'default'; }, myRadioModeButtonChecked: function () { this.$refs.myButtonGroup.mode = 'radio'; }, myCheckBoxModeButtonChecked: function () { this.$refs.myButtonGroup.mode = 'checkbox'; }, groupOnBtnClick: function (event) { let clickedButton = event.args.button; this.$refs.myLog.innerHTML = `Clicked: ${clickedButton[0].id}`; } } }</script> <style></style>