Custom Elements Documentation
Getting Started
jqxToolBar is a HTML Element which displays a bar with tools such as buttons, drop-downs and others.Every UI element from jQWidgets toolkit needs its JavaScript files to be included in order to work properly.
The first step is to create html page and add links to the javascript files and
css dependencies to your project.
The jqxToolBar element requires the following
files:
The next step is to add the html element within the body of the html page.<script type="text/javascript" src="../scripts/webcomponents-lite.min.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxcore.elements.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxdata.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxtoolbar.js"></script>
The last step is to initialize the element settings:<jqx-tool-bar settings="elementSettings"></jqx-tool-bar>
To call a function(method), you need to pass the method name and parameters(if any) in the jqxToolBar's instance.<script type="text/javascript">
JQXElements.settings["elementSettings"] =
{
tools:tools, initTools:initTools, theme:"light"
}
</script>
To get the result of a function after calling it, you can use the following syntax:<script>
window.onload = function () {
var element = document.querySelector("jqx-tool-bar");
element.addTool('button','first','',null);
}
</script>
To set a property(option), you need to use the property name and value(s) along with the jqxToolBar's instance.<script>
window.onload = function () {
var element = document.querySelector("jqx-tool-bar");
var result = element.getTools();
}
</script>
You can also set properties of HTML Elements by using Attributes. Traditionally, attributes are used to set the initial state of an element. Properties with camelCase naming have dash-based attributes. For example: A property "dataSource" will have an attribute called "data-source".window.onload = function() {
document.querySelector("jqx-tool-bar").height = 35;
}
To get a property(option), you need to use the property name along with the jqxToolBar's instance.
window.onload = function() {
var propertyValue = document.querySelector("jqx-tool-bar").height;
}
Event binding can be defined in the HTML as an attribute. The syntax is: 'on-' and the event's name. Event Names with camelCase naming have dash-based attributes. The attribute's value is the event handler's name. The addEventListener
function can also be used for event binding.
<script>
window.onload = function () {
var element = document.querySelector("jqx-tool-bar");
element.addEventListener("close", function(event){
// Your code here
});
}
</script>
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title id='Description'>Toolbar Custom Element Overview</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" />
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.light.css" type="text/css" />
<link rel="stylesheet" href="../../styles/demos.css" type="text/css" />
<script type="text/javascript" src="../../scripts/webcomponents-lite.min.js"></script><script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script><script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script><script type="text/javascript" src="../../jqwidgets/jqxcore.elements.js"></script><script type="text/javascript" src="../../../jqwidgets/jqxbuttons.js"></script><script type="text/javascript" src="../../../jqwidgets/jqxscrollbar.js"></script><script type="text/javascript" src="../../../jqwidgets/jqxlistbox.js"></script><script type="text/javascript" src="../../../jqwidgets/jqxdropdownlist.js"></script><script type="text/javascript" src="../../../jqwidgets/jqxcombobox.js"></script><script type="text/javascript" src="../../../jqwidgets/jqxinput.js"></script><script type="text/javascript" src="../../../jqwidgets/jqxtoolbar.js"></script><script type="text/javascript" src="../../scripts/demos.js"></script><script type="text/javascript">var initTools = function (type, index, tool, menuToolIninitialization) {if (type == "toggleButton") {var icon = document.createElement('div');icon.classList.add('jqx-editor-toolbar-icon');icon.classList.add('buttonIcon');tool[0].style.height = "27px";}switch (index) {case 0:icon.classList.add('jqx-editor-toolbar-icon-bold');icon.style.marginTop = '-2px';tool[0].appendChild(icon);break;case 1:icon.classList.add('jqx-editor-toolbar-icon-italic');icon.style.marginTop = '-2px';tool[0].appendChild(icon);break;case 2:icon.classList.add('jqx-editor-toolbar-icon-underline');icon.style.marginTop = '-2px';tool[0].appendChild(icon);break;case 3:new jqxDropDownList(tool, { width: 130, autoDropDownHeight: true, source: ["<span style='font-family: Courier New;'>Courier New</span>", "<span style='font-family: Times New Roman;'>Times New Roman</span>", "<span style='font-family: Verdana;'>Verdana</span>"], selectedIndex: 1 });break;case 4:new jqxComboBox(tool, { width: 50, autoDropDownHeight: true, source: [8, 9, 10, 11, 12, 14, 16, 18, 20], selectedIndex: 3 });break;case 5:new jqxInput(tool, { height: 25, width: 200, placeHolder: "Type here to search..." });break;}};var tools = 'toggleButton toggleButton toggleButton | dropdownlist combobox | input'JQXElements.settings["toolbarSettings"] ={tools:tools, initTools:initTools, theme:"light"}</script></head><body><jqx-tool-bar settings="toolbarSettings"></jqx-tool-bar></body></html>