aspnetbootstrap-119133-site-navigation-toolbar.md
The BootstrapToolbar control is a set of buttons arranged in groups.
The main Bootstrap Toolbar features are:
Use the control’s Items collection to populate it with buttons. Root-level toolbar items are instances of the BootstrapToolbarItem class. Each button can display an icon, a text or both. You can customize buttons to turn them into the following types:
<dx:BootstrapToolbar runat="server">
<Items>
<dx:BootstrapToolbarItem Name="Copy" IconCssClass="fa fa-copy" />
<dx:BootstrapToolbarItem Name="Paste" IconCssClass="fa fa-paste" />
<dx:BootstrapToolbarItem Name="Item1" Text="Item" />
<dx:BootstrapToolbarItem Name="Link" Text="Link" NavigateUrl="#DefaultToolbar" />
</Items>
</dx:BootstrapToolbar>
Child items are specified as BootstrapToolbarMenuItem objects that belong the parent item’s Items collection.
<dx:BootstrapToolbar runat="server">
<Items>
<dx:BootstrapToolbarItem Text="Zoom" Icon="fa fa-zoom" BeginGroup="true">
<Item Text="100%"></Item>
<Item Text="90%"></Item>
<Item Text="75%"></Item>
<Item Text="50%"></Item>
</dx:BootstrapToolbarItem>
</Items>
</dx:BootstrapToolbar>
The Radio Group UI specifies that only one toolbar item within a group can be checked at a time. To enable this functionality, specify equal GroupName properties for toolbar items that should be used as a Radio Group.
<dx:BootstrapToolbar runat="server">
<Items>
<dx:BootstrapToolbarItem GroupName="align" IconCssClass="fa fa-align-left" />
<dx:BootstrapToolbarItem GroupName="align" IconCssClass="fa fa-align-center" />
<dx:BootstrapToolbarItem GroupName="align" IconCssClass="fa fa-align-right" />
</Items>
</dx:BootstrapToolbar>
Set a toolbar item’s GroupName property to a unique value to force the item to change its checked state on every click.
<dx:BootstrapToolbar runat="server">
<Items>
<dx:BootstrapToolbarItem GroupName="UniqueGroupName" IconCssClass="fa fa-adjust" />
<dx:BootstrapToolbarItem IconCssClass="fa fa-bell">
<Items>
...
</Items>
</dx:BootstrapToolbarItem>
</Items>
</dx:BootstrapToolbar>
Use the Template property to create a custom toolbar item.
<dx:BootstrapToolbar runat="server">
<Items>
<dx:BootstrapCustomToolbarItem>
<Template>
<div class="d-flex align-items-center">
...
</div>
</Template>
</dx:BootstrapCustomToolbarItem>
</Items>
</dx:BootstrapToolbar>
Use the DataSourceID property to bind a Toolbar control to a data source object. The object should implement the IHierarchicalEnumerable or IHierarchicalDataSource interface.
A data-bound Toolbar automatically creates a toolbar item for each data item. A created item’s properties obtain values from data item attributes with corresponding names. You can also use the following properties to explicitly specify the mapping between toolbar item properties and data item attribute names:
BeginGroupField – Specifies the data source field that identifies toolbar items that should start a group.
IconCssClassField - Specifies the data source field that provides names of CSS classes that define the toolbar items’ images.
NameField - Specifies the name of a data field that provides toolbar item’s names.
NavigateUrlField - Specifies the name of a data field that provides URLs that are opened when the toolbar item is clicked.
TextField - Specifies the name of a data field that provides toolbar item’s text.
ToolTipField - Specifies the name of a data field that provides the tooltip text for toolbar items.
<dx:BootstrapToolbar runat="server" DataSourceID="ToolbarDataSource" TextField="Text" NameField="Name" BeginGroupField="BeginGroup" IconCssClassField="Icon">
</dx:BootstrapToolbar>
<asp:XmlDataSource ID="ToolbarDataSource" runat="server" DataFile="~/App_Data/ToolbarItems.xml" XPath="/Toolbar/*"></asp:XmlDataSource>
<?xml version="1.0" encoding="utf-8" ?>
<Toolbar>
<Item Name="Print" Icon="fa fa-print"></Item>
<Item Name="Undo" Icon="fa fa-undo"></Item>
<Item Name="Redo" Icon="fa fa-redo"></Item>
<Item Name="Plain Format" Icon="fa fa-paint-brush"></Item>
<Item Text="Zoom" Icon="fa fa-zoom" BeginGroup="true">
<Item Text="100%"></Item>
<Item Text="90%"></Item>
<Item Text="75%"></Item>
<Item Text="50%"></Item>
</Item>
<Item Name="Bold" Icon="fa fa-bold" BeginGroup="True"></Item>
<Item Name="Italic" Icon="fa fa-italic"></Item>
<Item Name="Underline" Icon="fa fa-underline"></Item>
<Item Name="LeftAlign" Icon="fa fa-align-left" BeginGroup="True"></Item>
<Item Name="CenterAlign" Icon="fa fa-align-center"></Item>
<Item Name="RightAlign" Icon="fa fa-align-right"></Item>
<Item Name="JustifyAlign" Icon="fa fa-align-justify"></Item>
</Toolbar>
Use the RenderOption property to specify contextual styles for the Toolbar’s root items.
<dx:BootstrapToolbar runat="server">
<Items>
<dx:BootstrapToolbarItem Text="Info">
<SettingsBootstrap RenderOption="Info" />
</dx:BootstrapToolbarItem>
<dx:BootstrapToolbarItem Text="Success">
<SettingsBootstrap RenderOption="Success" />
</dx:BootstrapToolbarItem>
</Items>
</dx:BootstrapToolbar>
The Bootstrap Toolbar control supports templates that allow you to customize the control’s appearance and layout. A template can be applied to all toolbar items (control-level templates) or a specific item (item-level templates).
<dx:BootstrapToolbar runat="server">
<ItemTemplate>
<span class="<%# Eval("IconCssClass") %>" data-toggle="tooltip" title="<%# Eval("Text") %>"></span>
</ItemTemplate>
<ClientSideEvents Init="onClipboardToolbarInit" />
<Items>
<dx:BootstrapToolbarItem Name="Paste" Text="Paste" IconCssClass="fa fa-2x fa-paste" />
<dx:BootstrapToolbarItem Name="Cut" Text="Cut" IconCssClass="fa fa-2x fa-cut fa-rotate-270" />
<dx:BootstrapToolbarItem Name="Copy" Text="Copy" IconCssClass="fa fa-2x fa-copy" />
</Items>
</dx:BootstrapToolbar>
function onClipboardToolbarInit(s, e) {
$('[data-toggle="tooltip"]').tooltip();
}
Control-level templates’ API:
Item-level templates’ API:
The Bootstrap Toolbar automatically adapts to container size change or to various target device sizes. The following settings allow you to control what happens when the toolbar cannot fit into its container:
The Title property specifies the toolbar title that is never hidden.
EnableCollapseRootItemsToIcons set to true hides the text of all items that contain icons. Additionally, you can use the item’s AdaptivePriority property to hide a specific item first of others.
EnableAutoHideRootItems set to true moves the root items one by one to the root submenu until the toolbar contains the minimum number of root items (specified by the MinRootItemsCount property).
You can set the AutoPostBack property to true to automatically initiate a postback when a user performs an action that can be handled on the server side (for example, clicks a toolbar item).
One of the following events is fired on the server in response to a postback:
On the client side, use the BootstrapClientToolbar class to interact with the control as specified below:
DevExpress Bootstrap controls are shipped with online feature-based demos. To preview the Bootstrap Toolbar and its features, click See Demos.
See Also