Vertical Grid Toolbars
- 5 minutes to read
The DevExpress ASPxVerticalGrid control enables you to group the most important or frequently used grid commands, and expose them through customizable toolbars for efficient end-user access.
See Online Demo: Toolbar
Note
The ASPxGridBase.KeyFieldName property should be specified when using the following grid features:
- data editing;
- adding new and deleting existing data item;
- selecting record.
Toolbar Object
The ASPxVerticalGrid stores toolbars in its ASPxVerticalGrid.Toolbars collection. Each toolbar is a VerticalGridToolbar class instance. You can add and remove toolbars in the collection and change the following characteristics of individual toolbars:
Toolbar Characteristic | Property | Description |
---|---|---|
Adaptive Behavior | GridToolbar.SettingsAdaptivity.Enabled | Specifies whether an adaptive behavior is enabled for the toolbar. |
Availability | GridToolbar.Enabled | Gets or sets a value that indicates whether the toolbar is enabled, allowing the toolbar to respond to end-user interactions. |
Item Alignment | GridToolbar.ItemAlign | Gets or sets the toolbar item alignment. |
Name | GridToolbar.Name | Gets or sets the toolbar’s unique identifier name. |
Position | GridToolbar.Position | Gets or sets the toolbar position. |
Visibility | GridToolbar.Visible | Gets or sets a value specifying the visibility of the toolbar. |
To populate a toolbar with toolbar items and to have indexed access to them, use the toolbar’s VerticalGridToolbar.Items property.
Toolbar Item Object
Toolbar items are instances of the VerticalGridToolbarItem class. It is a descendant of the MenuItem class and so it inherits the following key functionality making a toolbar item appear and behave as a menu item.
Toolbar Item Characteristic | Property | Description |
---|---|---|
Group Separation | MenuItem.BeginGroup | Gets or sets a value that specifies whether the current menu item starts a group. |
Group Name | MenuItem.GroupName | Gets or sets the name of a logical check group to which the menu item belongs. |
Image | MenuItem.Image | Gets the settings of an image displayed within the menu item. |
Name | MenuItem.Name | Gets or sets the unique identifier name for the current menu item. |
Template | MenuItem.Template | Gets or sets a template used to display the content of the current menu item. |
Text | MenuItem.Text | Gets or sets the text content of the current menu item. |
Tooltip | MenuItem.ToolTip | Gets or sets the current menu item’s tooltip text. |
Additionally, you can use the following options explicitly implemented for toolbar items to properly customize their behavior and appearance.
Toolbar Item Characteristic | Property | Description |
---|---|---|
Display Mode | GridToolbarItem.DisplayMode | Gets or sets the display mode of the current toolbar item within the toolbar. |
Command to Execute | VerticalGridToolbarItem.Command | Gets or sets the name of a command executed when clicking a toolbar item. |
Child Items | VerticalGridToolbarItem.Items | Gets a collection that contains the toolbar items of the current toolbar item. Enables you to create hierarchies of nested toolbar items of unlimited depth. |
Based on the VerticalGridToolbarItem.Command property setting, a toolbar item either triggers a standard grid command (that is, data item editing, deletion, creation, etc.) or performs a custom action, if required (this action should be implemented programmatically).
Standard Toolbar Item
To make a toolbar item execute a standard command, set the item’s VerticalGridToolbarItem.Command property to the desired command name listed by the VerticalGridToolbarCommand enumeration. A standard toolbar item automatically displays the command-related text and image (optional). Clicking a standard toolbar item executes the corresponding grid command.
Example - How to create standard items
The code snippet below demonstrates how to create two standard toolbar items - for the New and Refresh commands - in the markup.
<dx:ASPxVerticalGrid runat="server" ID="Grid" ...>
...
<Toolbars>
<dx:VerticalGridToolbar ItemAlign="Right">
<Items>
<dx:VerticalGridToolbarItem Command="New" />
...
<dx:VerticalGridToolbarItem Command="Refresh" BeginGroup="true" />
...
</Items>
</dx:VerticalGridToolbar>
</Toolbars>
</dx:ASPxVerticalGrid>
Custom Toolbar Item
If you need a toolbar item to perform a custom action, create a new VerticalGridToolbarItem object and use one of the following two implementation options.
Use Toolbar-Related Grid API
Perform the following steps to identify the toolbar item and handle its clicks.
Set Command to Custom
Set the toolbar item’s VerticalGridToolbarItem.Command property to the VerticalGridToolbarCommand.Custom value (this is the default property setting).
Set Name
Specify a custom command name through the toolbar item’s MenuItem.Name property.
Set Text or Image
Specify item characteristics (such as text, image, or both) using the item’s MenuItem.Text and MenuItem.Image properties together with the GridToolbarItem.DisplayMode property.
Handle Event(s)
Handle the client ASPxClientGridBase.ToolbarItemClick event or server ASPxVerticalGrid.ToolbarItemClick event (or both) to identify the triggered custom command by its name and execute the required action.
Use a Template to Define Item
Create the toolbar item’s template using the MenuItem.Template property to define the item content and provide custom logic to implement the item behavior.
Example - How to create custom items (specifying their names, texts and images)
The code below demonstrates how to create a custom ‘Export to’ toolbar item with three sub-items to export the grid data to different formats (PDF, XLSX and XLS).
<dx:ASPxVerticalGrid runat="server" ID="Grid" OnToolbarItemClick="Grid_ToolbarItemClick" ...>
<Toolbars>
<dx:VerticalGridToolbar ItemAlign="Right">
<Items>
...
<dx:VerticalGridToolbarItem Text="Export to" Image-IconID="actions_download_16x16office2013" BeginGroup="true">
<Items>
<dx:VerticalGridToolbarItem Name="ExportToPDF" Text="PDF" Image-IconID="export_exporttopdf_16x16office2013" />
<dx:VerticalGridToolbarItem Name="ExportToXLSX" Text="XLSX" Image-IconID="export_exporttoxlsx_16x16office2013" />
<dx:VerticalGridToolbarItem Name="ExportToXLS" Text="XLS" Image-IconID="export_exporttoxls_16x16office2013" />
</Items>
</dx:VerticalGridToolbarItem>
...
</Items>
</dx:VerticalGridToolbar>
</Toolbars>
...
<ClientSideEvents ToolbarItemClick="OnToolbarItemClick" />
</dx:ASPxVerticalGrid>
<dx:ASPxVerticalGridExporter ID="Exporter" VerticalGridID="Grid" runat="server" />
Example - How to create a custom item (defining its template)
The following code illustrates how to create a custom toolbar item by defining its template to imitate the functionality of the grid search panel’s editor.
<dx:ASPxVerticalGrid runat="server" ID="Grid" ...>
<Toolbars>
<dx:VerticalGridToolbar ItemAlign="Right">
<Items>
...
<dx:VerticalGridToolbarItem BeginGroup="true">
<Template>
<dx:ASPxButtonEdit ID="tbToolbarSearch" runat="server" NullText="Search..." Height="100%">
<Buttons>
<dx:SpinButtonExtended Image-IconID="find_find_16x16gray" />
</Buttons>
</dx:ASPxButtonEdit>
</Template>
</dx:VerticalGridToolbarItem>
</Items>
</dx:VerticalGridToolbar>
</Toolbars>
...
<SettingsSearchPanel CustomEditorID="tbToolbarSearch" />
...
</dx:ASPxVerticalGrid>