Vue UI Components Documentation
The Vue ButtonGroup enables the creation of groups of buttons. This guide adds the Vue ButtonGroup (jqxButtonGroup) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-scriptsjqwidgets-scripts/jqwidgets-vue3/vue_jqxbuttongroup.vue In a Vue 3 project (to start one, see Getting started with Vue), add the package:
npm install jqwidgets-scripts
import JqxButtonGroup from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxbuttongroup.vue';
import 'jqwidgets-scripts/jqwidgets/styles/jqx.base.css';
import 'jqwidgets-scripts/jqwidgets/styles/jqx.tailwind-blue-dark.css';
With <script setup>, an imported component is ready to use in the template. jqx.base.css is required; the second file is a theme, selected with the theme attribute.
The Button Group demo as a Single-File Component:
<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 setup>
import { ref } from 'vue';
import JqxButtonGroup from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxbuttongroup.vue';
import JqxRadioButton from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxradiobutton.vue';
const myButtonGroup = ref(null);
const myLog = ref(null);
function myDefaultModeButtonChecked() {
myButtonGroup.value.mode = 'default';
}
function myRadioModeButtonChecked() {
myButtonGroup.value.mode = 'radio';
}
function myCheckBoxModeButtonChecked() {
myButtonGroup.value.mode = 'checkbox';
}
function groupOnBtnClick(event) {
let clickedButton = event.args.button;
myLog.value.innerHTML = `Clicked: ${clickedButton[0].id}`;
}
</script>
<style></style>
Options are attributes. Bind values from the script with :, for example :width="850".
Listen to an event with @ and its name. For example, buttonclick: This event is triggered when a button is clicked.
<script setup>
function onButtonclick(event) {
console.log(event.args);
}
</script>
<template>
<JqxButtonGroup @buttonclick="onButtonclick" />
</template>
Call methods through a template ref. For example, disableAt: Disables a button at specific index.
<script setup>
import { ref, onMounted } from 'vue';
const myButtonGroup = ref(null);
onMounted(() => {
myButtonGroup.value.disableAt(1);
});
</script>
<template>
<JqxButtonGroup ref="myButtonGroup" />
</template>
Every component also has setOptions({ … }) and getOptions('name').