| layout | post |
|---|---|
| title | Properties, Methods and Events of GroupButton Widget |
| description | API reference for GroupButton |
| documentation | API |
| platform | angular-api |
| keywords | GroupButton, Essential Angular GroupButton, GroupButton api |
The Essential JavaScript Group Button widget helps to display multiple buttons which are stacked together in a single line and used as a navigation component. Also it manages the checked/unchecked state for a set of buttons, since it supports radio and check button modes.
{% highlight html %}
{% endhighlight %}
{% highlight html %}
<ej-groupbutton [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
export class AppComponent { data: Object; constructor() { this.data = [ { text: "Day", contentType: "textonly" }, { text: "Week", contentType: "textonly" }, { text: "Month", contentType: "textonly", selected: "selected" }, { text: "Year", contentType: "textonly" }]; }; }
{% endhighlight %}
-
module:jQuery
-
module:ej.core.js
-
module:ej.groupbutton.js
{:#members:cssclass}
Sets the specified class to GroupButton wrapper element, which allows for custom skinning option in ejGroupButton control.
- ""
{% highlight html %}
<ej-groupbutton [(dataSource)]="data" [cssClass]="customCss">
{% endhighlight %}
{% highlight ts %}
export class AppComponent { data: Object; customCss: string; constructor() { this.data = [ { text: "Day", contentType: "textonly" }, { text: "Week", contentType: "textonly" }, { text: "Month", contentType: "textonly", selected: "selected" }, { text: "Year", contentType: "textonly" }]; }; this.customCss= "e-btnColor"; }
{% endhighlight %}
{:#members:datasource}
To set the local JSON data, define a JSON array and initialize the GroupButton with dataSource property. Specify the column names in the fields property.
- null
{% highlight html %}
<ej-groupbutton [(dataSource)]="data" [showRoundedCorner]="true">
{% endhighlight %}
{% highlight ts %}
export class AppComponent { data: Object; constructor() { this.data = [ { text: "Day", contentType: "textonly" }, { text: "Week", contentType: "textonly" }, { text: "Month", contentType: "textonly", selected: "selected" }, { text: "Year", contentType: "textonly" }]; }; }
{% endhighlight %}
{:#members:enablertl}
Displays the ejGroupButton in Right to Left direction.
- false
{% highlight html %}
<ej-groupbutton [(dataSource)]="data" [enableRTL]="true">
{% endhighlight %}
{% highlight ts %}
export class AppComponent { data: Object; constructor() { this.data = [ { text: "Day", contentType: "textonly" }, { text: "Week", contentType: "textonly" }, { text: "Month", contentType: "textonly", selected: "selected" }, { text: "Year", contentType: "textonly" }]; }; }
{% endhighlight %}
{:#members:enabled}
Used to enable or disable the ejGroupButton control.
- true
{% highlight html %}
<ej-groupbutton [(dataSource)]="data" [enabled]="false">
{% endhighlight %}
{% highlight ts %}
export class AppComponent { data: Object; constructor() { this.data = [ { text: "Day", contentType: "textonly" }, { text: "Week", contentType: "textonly" }, { text: "Month", contentType: "textonly", selected: "selected" }, { text: "Year", contentType: "textonly" }]; }; }
{% endhighlight %}
{:#members:fields}
Gets or sets a value that indicates to display the values of the data.
- null
Specifies the content type of the button. Button can have image only, text only, imagetextimage, textandimage, or imageboth as content type.
Specifies the HTML attributes to the element.
Specifies the image position in the button. This property is applicable for the content type 'textandimage' only.
Specifies the link attributes to the element.
Specifies the primary icon for button. This icon will be displayed from the left margin of the button.
Specifies the button is in selected state.
Specifies the secondary icon for button. This icon will be displayed from the right margin of the button.
Specifies the text in the button.
Specifies the URL of the button for navigation.
{% highlight html %}
<ej-groupbutton [(dataSource)]="data" [(fields)]="fields">
{% endhighlight %}
{% highlight ts %}
export class AppComponent { data: Object; fields: Object; constructor() { this.data = [ { text: "Day", contentType: "textonly" }, { text: "Week", contentType: "textonly" }, { text: "Month", contentType: "textonly", selected: "selected" }, { text: "Year", contentType: "textonly" }, ]; this.fields= { contentType :"contentType", text:"text", selected: "selected" }; } }
{% endhighlight %}
{:#members:groupbuttonmode}
Sets the GroupButton behavior to works as Checkbox mode/ radio button mode based on the specified option.
| Name | Description |
|---|---|
| CheckBox | Sets the GroupButton to work as checkbox mode |
| RadioButton | Sets the RadioButton to work as radio button mode |
- ej.GroupButtonMode.RadioButton
{% highlight html %}
<ej-groupbutton [(dataSource)]="data" [groupButtonMode]="groupButtonMode">
{% endhighlight %}
{% highlight ts %}
export class AppComponent { data: Object; groupButtonMode: any; constructor() { this.data = [ { text: "Day" }, { text: "Week" }, { text: "Month" }, { text: "Year" } ]; this.groupButtonMode = ej.GroupButtonMode.RadioButton; } }
{% endhighlight %}
{:#members:height}
Used to sets the height of the ejGroupButton control.
- 28
{% highlight html %}
<ej-groupbutton [(dataSource)]="data" [height]="height">
{% endhighlight %}
{% highlight ts %}
export class AppComponent {
data: Object;
height: number;
constructor() {
this.data = [
{ text: "Day" },
{ text: "Week" },
{ text: "Month" },
{ text: "Year" }
];
this.height = 40;
}
}
{% endhighlight %}
{:#members:htmlattributes}
Defines the characteristics of the ejGroupButton control and extend the capability of an HTML element by adding specified attributes to element tag and by performing the related actions
- {}
{% highlight html %}
<ej-groupbutton [(dataSource)]="data" [htmlAttributes]="htmlAttributes">
{% endhighlight %}
{% highlight ts %}
export class AppComponent {
data: Object;
htmlAttributes: any;
constructor() {
this.data = [
{ text: "Day" },
{ text: "Week" },
{ text: "Month" },
{ text: "Year" }
];
this.htmlAttributes = { title: "Group Button" };
}
}
{% endhighlight %}
{:#members:orientation}
Specify the orientation of the GroupButton. See below to get available orientations
| Name | Type | Default | Description |
|---|---|---|---|
| Horizontal | string | horizontal | Enum for Horizontal Orientation |
| Vertical | string | vertical | Enum for Vertical Orientation |
- ej.Orientation.Horizontal
{% highlight html %}
<ej-groupbutton [(dataSource)]="data" [orientation]="orientation">
{% endhighlight %}
{% highlight ts %}
export class AppComponent {
data: Object;
orientation: any;
constructor() {
this.data = [
{ text: "Day" },
{ text: "Week" },
{ text: "Month" },
{ text: "Year" }
];
this.orientation = ej.Orientation.Vertical;
}
}
{% endhighlight %}
{:#members:query}
Query the dataSource from the table for Groupbutton
{:.param}
- null
{% highlight ts %}
<ej-groupbutton [(dataSource)]="data" [query]="query" [fields]="fields">
{% endhighlight %}
{% highlight ts %}
import {Component, ViewEncapsulation} from '@angular/core';
import {NorthwindService} from './services/northwind.service';
@Component({
selector: 'ej-app',
templateUrl: 'app/app.component.html',
providers:[NorthwindService]
})
export class AppComponent {
data: Object;
dataManager: any;
query:any;
fields:Object;
constructor()
{
this.dataManager = ej.DataManager({
url: "http://mvc.syncfusion.com/Services/Northwnd.svc/Orders/",
crossDomain:true
});
this.data = this.dataManager;
this.query = ej.Query().from("Orders").take(6);
this.fields = { text: "CustomerID" };
}
}
{% endhighlight %}
{:#members:selecteditemindex}
Sets the list of button elements to be selected. To enable this option groupButtonMode should be in “checkbox” mode.
- []
{% highlight html %}
<ej-groupbutton [(dataSource)]="data" [groupButtonMode]="groupButtonMode" [selectedItemIndex]="selectedItemIndex">
{% endhighlight %}
{% highlight ts %}
export class AppComponent {
data: Object;
groupButtonMode: any;
selectedItemIndex: string[];
constructor() {
this.data = [
{ text: "Day" },
{ text: "Week" },
{ text: "Month" },
{ text: "Year" }
];
this.groupButtonMode = "checkbox";
this.selectedItemIndex = ["1","2"];
}
}
{% endhighlight %}
{:#members:showroundedcorner}
Sets the rounder corner to the GroupButton, if sets as true.
- false
{% highlight html %}
<ej-groupbutton [(dataSource)]="data" [showRoundedCorner]="true">
{% endhighlight %}
{% highlight ts %}
export class AppComponent {
data: Object;
constructor() {
this.data = [
{ text: "Day" },
{ text: "Week" },
{ text: "Month" },
{ text: "Year" }
];
}
}
{% endhighlight %}
{:#members:size}
Specifies the size of the button. See available size
- ej.ButtonSize.Normal
{% highlight html %}
<ej-groupbutton [(dataSource)]="data" [size]="size">
{% endhighlight %}
{% highlight ts %}
export class AppComponent {
data: Object;
size: any;
constructor() {
this.data = [
{ text: "Day" },
{ text: "Week" },
{ text: "Month" },
{ text: "Year" }
];
this.size=ej.ButtonSize.Large;
}
}
{% endhighlight %}
{:#members:width}
Defines the width of the ejGroupButton control.
- ""
{% highlight html %}
<ej-groupbutton [(dataSource)]="data" [width]="width">
{% endhighlight %}
{% highlight ts %}
export class AppComponent {
data: Object;
width: string;
constructor() {
this.data = [
{ text: "Day" },
{ text: "Week" },
{ text: "Month" },
{ text: "Year" }
];
this.width="100%";
}
}
{% endhighlight %}
{:#methods:deselectitem}
Remove the selection state of the specified the button element from the GroupButton
| Parameters | Type | Description |
| element | jQuery | Specific button element |
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
//create the instance to the ejGroupButton var groupButtonObj = $("#groupButton").ejGroupButton('instance'); groupButtonObj.deselectItem(getSelectedItem());
{% endhighlight %}
{:#methods:destroy}
Destroy the GroupButton widget all events bound using this._on will be unbind automatically and bring the control to pre-init state.
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
//create the instance to the ejGroupButton var groupButtonObj = $("#groupButton").ejGroupButton('instance'); groupButtonObj.destroy(); // destroy the GroupButton
{% endhighlight %}
{:#methods:disable}
Disables the GroupButton control
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
//create the instance to the ejGroupButton var groupButtonObj = $("#groupButton").ejGroupButton('instance'); groupButtonObj.disable();
{% endhighlight %}
{:#methods:disableitem}
Disable the specified button element from the ejGroupButton control.
| Parameters | Type | Description |
| element | jQuery | Specific button element |
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
//create the instance to the ejGroupButton
var groupButtonObj =
{% endhighlight %}
{:#methods:enable}
Enables the disabled ejGroupButton control.
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
//create the instance to the ejGroupButton var groupButtonObj = $("#groupButton").ejGroupButton('instance'); groupButtonObj.enable();
{% endhighlight %}
{:#methods:enableitem}
Enable the specified disabled button element from the ejGroupButton control.
| Parameters | Type | Description |
| element | jQuery | Specific button element |
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
//create the instance to the ejGroupButton
var groupButtonObj =
{% endhighlight %}
{:#methods:getindex}
Returns the index value for specified button element in the GroupButton control.
| Parameters | Type | Description |
| element | jQuery | Specific button element |
number
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
//create the instance to the ejGroupButton
var groupButtonObj =
{% endhighlight %}
{:#methods:getselecteditem}
This method returns the list of active state button elements from the GroupButton control.
object
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
//create the instance to the ejGroupButton var groupButtonObj = $("#groupButton").ejGroupButton('instance'); groupButtonObj.getSelectedItem();
{% endhighlight %}
{:#methods:hide}
Hides the GroupButton control
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
//create the instance to the ejGroupButton var groupButtonObj = $("#groupButton").ejGroupButton('instance'); groupButtonObj.hide();
{% endhighlight %}
{:#methods:hideitem}
Hide the specified button element from the ejGroupButton control.
| Parameters | Type | Description |
| element | jQuery | Specific button element |
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
//create the instance to the ejGroupButton
var groupButtonObj =
{% endhighlight %}
{:#methods:isdisabled}
Returns the disabled state of the specified element button element in GroupButton as Boolean.
boolean
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
//create the instance to the ejGroupButton
var groupButtonObj =
{% endhighlight %}
{:#methods:isselected}
Returns the state of the specified button element as Boolean.
boolean
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
//create the instance to the ejGroupButton
var groupButtonObj =
{% endhighlight %}
{:#methods:selectitem}
Public method used to select the specified button element from the ejGroupButton control.
| Parameters | Type | Description |
| element | jQuery | Specific button element |
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
//create the instance to the ejGroupButton
var groupButtonObj =
{% endhighlight %}
{:#methods:show}
Shows the GroupButton control, if its hide.
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
//create the instance to the ejGroupButton var groupButtonObj = $("#groupButton").ejGroupButton('instance'); groupButtonObj.show();
{% endhighlight %}
{:#methods:showitem}
Show the specified hidden button element from the ejGroupButton control.
| Parameters | Type | Description |
| element | jQuery | Specific button element |
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data">
{% endhighlight %}
{% highlight ts %}
//create the instance to the ejGroupButton
var groupButtonObj =
{% endhighlight %}
{:#events:beforeselect}
Triggered before any button element in the GroupButton get selected.
| Name | Type | Description |
|---|---|---|
| disabled | boolean | Boolean value based on whether the button element is disabled or not. |
| element | object | Returns the selection button element. |
| event | object | Event object |
| id | string | Return the button element ID. |
| index | number | Button item index. |
| model | object | returns the button model |
| selected | boolean | Boolean value based on whether the button element is selected or not. |
| type | string | returns the name of the event |
| status | boolean | return the button state |
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data" (beforeSelect)="onBeforeSelect($event)">
{% endhighlight %}
{% highlight ts %}
export class AppComponent { constructor(){ } onBeforeSelect(e: any){ //Your code here }
}
{% endhighlight %}
{:#events:create}
Fires after GroupButton control is created.If the user want to perform any operation after the button control creation then the user can make use of this create event.
| Name | Type | Description |
|---|---|---|
| cancel | boolean | if the event should be canceled; otherwise, false. |
| model | object | returns the GroupButton model |
| type | string | returns the name of the event |
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data" (create)="onCreate($event)">
{% endhighlight %}
{% highlight ts %}
export class AppComponent { constructor(){ } onCreate(e: any){ // Your code here }
}
{% endhighlight %}
{:#events:destroy}
Fires when the GroupButton is destroyed successfully.If the user want to perform any operation after the destroy button control then the user can make use of this destroy event.
| Name | Type | Description |
|---|---|---|
| cancel | boolean | if the event should be canceled; otherwise, false. |
| model | object | returns the GroupButton model |
| type | string | returns the name of the event |
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data" (destroy)="onDestroy($event)">
{% endhighlight %}
{% highlight ts %}
export class AppComponent { constructor(){ } onDestroy(e: any){ // Your code here }
}
{% endhighlight %}
{:#events:keypress}
Triggered once the key is pressed, when the control is in focused state.
| Name | Type | Description |
|---|---|---|
| disabled | boolean | Boolean value based on whether the button element is disabled or not. |
| element | object | Returns the selection button element. |
| event | object | Event object |
| id | string | Return the button element ID. |
| index | number | Button item index. |
| model | object | returns the button model |
| selected | boolean | Boolean value based on whether the button element is selected or not. |
| type | string | returns the name of the event |
| status | boolean | return the button state |
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data" (keyPress)="onKeyPress($event)">
{% endhighlight %}
{% highlight ts %}
export class AppComponent { constructor(){ } onKeyPress(e: any){ // Your code here }
}
{% endhighlight %}
{:#events:select}
Triggered when the button element get selected.
| Name | Type | Description |
|---|---|---|
| disabled | boolean | Boolean value based on whether the selected button element is disabled or not. |
| element | object | Returns the selection button element. |
| event | object | Event object |
| id | string | Return the selected button element ID. |
| index | number | Selected button item index. |
| model | object | returns the button model |
| selected | boolean | Boolean value based on whether the button element is selected or not. |
| type | string | returns the name of the event |
| status | boolean | return the button state |
{% highlight html %}
<ej-groupbutton id="groupButton" [(dataSource)]="data" (select)="onSelect($event)">
{% endhighlight %}
{% highlight ts %}
export class AppComponent { constructor(){ } onSelect(e: any){ // Your code here }
}
{% endhighlight %}