The Toolbar can be rendered by defining an array of items
. Items can be constructed with the following built-in command types or item template.
Button
is the default command type
, and it can be rendered by using the text
property.
Properties of the button command type:
Property | Description |
---|---|
text |
The text to be displayed for button. |
id |
The ID of the button to be rendered. If the ID is not given, auto ID is generated. |
prefixIcon |
Defines the class used to specify an icon for the button. The icon is positioned before the text if text is available or the icon alone button is rendered. |
suffixIcon |
Defines the class used to specify an icon for the button. The icon is positioned after the text if text is available. If both prefixIcon and suffixIcon are specified, only prefixIcon is considered. |
width |
Used to set the width of the button. |
align |
Specifies the location for aligning Toolbar items. |
The Separator
type adds a vertical separation between the Toolbar’s single/multiple commands.
ej.base.enableRipple(true);
//Initialize Toolbar component
var toolbar = new ej.navigations.Toolbar({
items: [
{ text: "Cut" },
{ text: "Copy" },
{ type: "Separator" },
{ text: "Paste" },
{ type: "Separator" },
{ text: "Undo" },
{ text: "Redo" }
]
});
//Render initialized Toolbar component
toolbar.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
<title>Essential JS 2 Toolbar</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Toolbar Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet">
<link href="https://ej2.syncfusion.com/angular/demos/src/toolbar/toolbar.component.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
<br><br>
<div id="result"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
If
Separator
is added as the first or the last item, it will not be visible.
The Input
type is only applicable for adding template
elements when the template
property is defined as an object
. Input type creates an input element
internally that acts as the container for Syncfusion
input based components.
NumericTextBox
component can be included by importing the NumericTextBox
module from ej2-inputs
.NumericTextBox
in template property, where the Toolbar item type is set as Input
.NumericTextBox
component properties can also be configured as given below.new NumericTextBox( { format: 'c2' }))
DropDownList
component can be included by importing the DropDownList
module from ej2-dropdowns
.DropDownList
in template property, where the Toolbar item type is set as Input
.DropDownList
component properties can also be configured as given below.new DropDownList({ width:100 })
CheckBox
component can be included by importing the CheckBox
module from ej2-buttons
.CheckBox
in template property, where the Toolbar item type is set as Input
.CheckBox
component properties can also be configured as given below.new CheckBox({ label: 'Default' })
RadioButton
component can be included by importing the RadioButton
module from ej2-buttons
.RadioButton
in template property, where the Toolbar item type is set as Input
.RadioButton
component properties can also be configured as given below.new RadioButton({ label: 'Option 1', name: 'default'})
The above steps are applicable for all ‘Syncfusion’ input based components.
E.g.: The following code explains how to add NumericTextBox
,DropDownList
,RadioButton
and CheckBox
components to the Toolbar.
ej.base.enableRipple(true);
//Initialize Toolbar component
var sportsData = ['Badminton', 'Cricket', 'Football', 'Golf', 'Tennis'];
var toolbar = new ej.navigations.Toolbar({
items: [
{ text: "Cut" },
{ text: "Copy" },
{ type: "Separator" },
{ text: "Undo" },
{ text: "Redo" },
{ type: "Separator" },
{ type: 'Input', template: new ej.inputs.NumericTextBox({ format: 'c2', value:1, width:150 }) },
{ type: 'Input', template: new ej.dropdowns.DropDownList({ dataSource: sportsData, width: 120, index: 2 }) },
{ type: 'Input', template: new ej.buttons.CheckBox({ label: 'Checkbox', checked: true }) },
{ type: 'Input', template: new ej.buttons.RadioButton({ label: 'Radio', name: 'default', checked: true }) },
]
});
//Render initialized Toolbar component
toolbar.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
<title>Essential JS 2 Toolbar</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Toolbar Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet">
<link href="https://ej2.syncfusion.com/angular/demos/src/toolbar/toolbar.component.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
<br><br>
<div id="result"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>