Button
The Button control displays a button with a text label and an optional icon. A button can switch between two states (twoState) and show a badge with a number, for example, to count new messages.
Related sample: Ribbon. Group buttons
Create a button
The following example shows the basic configuration of a button:
{
type:"button", value:"Best button"
}
Properties
Check the list of properties that you can set in the configuration object of a Button control.
Add a button
Use the add() method of TreeCollection to add a button to a ribbon block:
ribbon.data.add({
type:"button", value:"Best button"
},-1,"blockId");
Add HTML content
Use the html property to add a custom element to a button:
{
type: "button",
html: "<div id='preloader'><div id='loader'></div></div >",
size: "auto"
}
Related sample: Ribbon. Item HTML content
Show and hide a button
The show() and hide() methods show and hide a button by its ID:
ribbon.show(id);
ribbon.hide(id);
Enable and disable a button
The enable() and disable() methods enable and disable a button by its ID:
ribbon.enable(id);
ribbon.disable(id);
Add an icon
Use the icon property to add an icon to a button:
{
type:"button", value:"Done",
icon:"dxi dxi-check"
}
Add a badge with a number
Set the count property to add a badge with a number to a button:
{
type:"button", value:"Done",
icon:"dxi dxi-check",
count:10
}
Related sample: Ribbon. Buttons configuration
Style buttons
Specify custom CSS classes in the css property to style a button:
{
type:"button", value:"Best button", css:"best_button"
}
Define the best_button class in your CSS:
.best_button{
background-color:cornflowerblue;
}
.best_button:hover{
background-color:rgb(183, 199, 228);
}
TwoState Buttons
Set the twoState property to create a button with two states: active (pressed) and inactive (unpressed). The active property sets the initial state:
{
type:"button", value:"Select", twoState:true, active:true
}
Change the button state
Use the setState() method of Ribbon to change the state of a TwoState button or the values of other controls:
{
type:"button", twoState:true, value:"Check", id:"check"
}
...
ribbon.setState({check:true}); // active:true
// or
ribbon.setState({check:false}); // active:false
The setState() method takes one parameter: a key-value pair with the ID of the button and the new value.
Get the button state
Use the getValues() method to get the current state of a TwoState button or the values of other controls:
{
type:"button", value:"Check", twoState:true, id:"check"
}
...
ribbon.getState();
// { check:true }
// or
// { check:false }