Card View Toolbars
- 5 minutes to read
The DevExpress ASPxCardView control enables you to group the most important or frequently used grid commands, and expose them through customizable toolbars - so that end users can access them easily.
See Online Demo: Toolbar
Note
The ASPxGridBase.KeyFieldName property should be specified if the following grid features are used:
- data editing;
- adding a new card or deleting an existing card;
- selecting a card;
- endless paging.
Toolbar Object
ASPxCardView stores toolbars in its ASPxCardView.Toolbars collection. Each toolbar is a CardViewToolbar class instance. You can add and remove toolbars within the collection and change the following characteristics of individual toolbars:
Toolbar Characteristic | Property | Description |
---|---|---|
Adaptive Behavior | GridToolbarSettingsAdaptivity.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 allow indexed access to them, use the toolbar’s CardViewToolbar.Items property.
Toolbar Item Object
Toolbar items are instances of the CardViewToolbarItem class. This class is a descendant of the MenuItem class, so it inherits the following key functionality that makes it look and behave like 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 | CardViewToolbarItem.Command | Gets or sets the name of a command executed when clicking a toolbar item. |
Child Items | CardViewToolbarItem.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 CardViewToolbarItem.Command property setting, a toolbar item either triggers a standard grid command (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 CardViewToolbarItem.Command property to the desired command name listed by the CardViewToolbarCommand enumeration. A standard toolbar item automatically displays the command-related text and image (optional). When an end user clicks a standard toolbar item, the corresponding grid command is executed.
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 markup.
<dx:ASPxCardView runat="server" ID="Grid" ...>
...
<Toolbars>
<dx:CardViewToolbar ItemAlign="Right">
<Items>
<dx:CardViewToolbarItem Command="New" />
...
<dx:CardViewToolbarItem Command="Refresh" BeginGroup="true" />
...
</Items>
</dx:CardViewToolbar>
</Toolbars>
</dx:ASPxCardView>
Custom Toolbar Item
If you require a toolbar item to perform a custom action, create a new CardViewToolbarItem object and use one of the following 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 CardViewToolbarItem.Command property to CardViewToolbarCommand.Custom (the default property setting).
Set Name
Use the toolbar item’s MenuItem.Name property to specify a custom command name.
Set Text or Image
Use the item’s MenuItem.Text and MenuItem.Image properties along with the GridToolbarItem.DisplayMode property to specify item characteristics (such as text, image, or both).
Handle Event(s)
Handle the client-side ASPxClientGridBase.ToolbarItemClick event or the server-side ASPxCardView.ToolbarItemClick event (or both) to identify the custom command by its name and execute the required action.
Use a Template to Define an Item
Use the MenuItem.Template property to create the toolbar item’s template - to define the item content and provide custom logic to implement the item behavior.
Example - How to create custom items (by specifying names, text and images)
The code below demonstrates how to create a custom ‘Export to’ toolbar item with three sub-items to export grid data to different formats (PDF, XLSX and XLS).
<dx:ASPxCardView runat="server" ID="Grid" OnToolbarItemClick="Grid_ToolbarItemClick" ...>
<Toolbars>
<dx:CardViewToolbar ItemAlign="Right">
<Items>
...
<dx:CardViewToolbarItem Text="Export to" Image-IconID="actions_download_16x16office2013" BeginGroup="true">
<Items>
<dx:CardViewToolbarItem Name="CustomExportToPDF" Text="PDF" Image-IconID="export_exporttopdf_16x16office2013" />
<dx:CardViewToolbarItem Name="CustomExportToXLS" Text="XLS(DataAware)" Image-IconID="export_exporttoxls_16x16office2013" />
<dx:CardViewToolbarItem Name="CustomExportToXLSX" Text="XLSX(WYSIWYG)" Image-IconID="export_exporttoxlsx_16x16office2013" />
</Items>
</dx:GridViewToolbarItem>
...
</Items>
</dx:CardViewToolbar>
</Toolbars>
...
<ClientSideEvents ToolbarItemClick="OnToolbarItemClick" />
</dx:ASPxCardView>
Example - How to create a custom item (by defining its template)
The following code creates a custom toolbar item by defining a template that imitates the functionality of the grid search panel’s editor.
<dx:ASPxCardView runat="server" ID="Grid" ...>
<Toolbars>
<dx:CardViewToolbar ItemAlign="Right">
<Items>
...
<dx:CardViewToolbarItem 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:CardViewToolbarItem>
</Items>
</dx:CardViewToolbar>
</Toolbars>
...
<SettingsSearchPanel CustomEditorID="tbToolbarSearch" />
...
</dx:ASPxCardView>