Angular UI Components Documentation
The Angular ButtonGroup enables the creation of groups of buttons. This guide adds the Angular ButtonGroup (jqxButtonGroup) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-ngjqwidgets-ng/jqxbuttongroup In an Angular project (to start one, see Getting started with Angular), add the package with the Angular CLI. It asks for a theme and adds the styles to angular.json:
ng add jqwidgets-ng
Components are standalone: add jqxButtonGroupModule to the imports of the component that uses it.
import { Component } from '@angular/core';
import { jqxButtonGroupModule } from 'jqwidgets-ng/jqxbuttongroup';
@Component({
selector: 'app-root',
imports: [jqxButtonGroupModule],
templateUrl: './app.html'
})
export class App {}
The source of the live Button Group demo.
<jqxButtonGroup #myButtonGroup (onButtonclick)="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 (onChecked)="radioButtonChecked('default')">Default</jqxRadioButton>
<jqxRadioButton (onChecked)="radioButtonChecked('radio')">RadioButtons</jqxRadioButton>
<jqxRadioButton (onChecked)="radioButtonChecked('checkbox')">CheckBoxes</jqxRadioButton>
</div>
<div #myLog style="margin-top: 10px;"></div>
import { Component, ElementRef, viewChild } from '@angular/core';
import { jqxButtonGroupComponent } from 'jqwidgets-ng/jqxbuttongroup';
import { CommonModule } from '@angular/common';
import { jqxButtonGroupModule } from 'jqwidgets-ng/jqxbuttongroup';
import { jqxRadioButtonModule } from 'jqwidgets-ng/jqxradiobutton';
@Component({
imports: [CommonModule, jqxButtonGroupModule, jqxRadioButtonModule],
selector: 'app-root',
templateUrl: './app.html'
})
export class App {
readonly myButtonGroup = viewChild.required<jqxButtonGroupComponent>('myButtonGroup');
readonly myLog = viewChild.required<ElementRef>('myLog');
public radioButtonChecked(mode: string): void {
this.myButtonGroup().mode(mode);
}
public groupOnBtnClick(event: any): void {
const clickedButton = event.args.button;
this.myLog().nativeElement.innerHTML = `Clicked: ${clickedButton[0].id}`;
}
}
Options are inputs, bound with [name]="value".
Events are outputs named on plus the event name with a capital first letter. For example, buttonclick: This event is triggered when a button is clicked.
<jqxButtonGroup (onButtonclick)="onButtonclick($event)"></jqxButtonGroup>
onButtonclick(event: any): void {
console.log(event.args);
}
Get the component with a signal query and call its methods. For example, disableAt: Disables a button at specific index.
<jqxButtonGroup #myButtonGroup></jqxButtonGroup>
import { Component, viewChild } from '@angular/core';
import { jqxButtonGroupModule, jqxButtonGroupComponent } from 'jqwidgets-ng/jqxbuttongroup';
@Component({
selector: 'app-root',
imports: [jqxButtonGroupModule],
templateUrl: './app.html'
})
export class App {
readonly myButtonGroup = viewChild.required<jqxButtonGroupComponent>('myButtonGroup');
run(): void {
this.myButtonGroup().disableAt(1);
}
}