DxToolbarDataMapping Class
Maps Toolbar item properties to data source fields.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v22.2.dll
NuGet Package: DevExpress.Blazor
Declaration
public class DxToolbarDataMapping :
DxToolbarDataMappingBase
Remarks
You can populate the Toolbar component with items from a data source.
Follow the steps below to bind Toolbar to data:
Use the Data property to specify a data source. You can use different data types:
- Flat data - a collection of items organized as a single-level structure.
- Hierarchical data - a collection of nested items.
Add the DataMappings tag to the component’s markup.
Create the
DxToolbarDataMapping
instance and map item properties (BeginGroup, NavigateUrl, and so on) to data source fields. Mappings are used to link the Toolbar data model to the data source.Flat data - use the Key and ParentKey properties to create a hierarchy of items. If the Toolbar’s structure is linear, you can omit these properties.
Hierarchical data - the Children property is required.
You can also create multiple
DxToolbarDataMapping
instances to specify different mappings for different item levels. Use the Level property to specify the item level for which data mappings are applied.
Flat Data
The code below binds the Toolbar to the flat collection of data items and specifies mappings for the Text, Key, and ParentKey properties.
<div class="card p-2">
<DxToolbar Data=@FormatItem.ToolbarItems>
<DataMappings>
<DxToolbarDataMapping Text="ValueName" Key="Id" ParentKey="ParentId" />
</DataMappings>
</DxToolbar>
</div>
Hierarchical Data
The code below binds the Toolbar to the collection of FormatItem
objects. Each object can have child objects. The code specifies the Children, Text, and Checked mappings to adjust the Toolbar’s data model to the specified data source.
<div class="card p-2">
<DxToolbar Data=@FormatItem.ToolbarItems ItemClick=@OnItemClicked>
<DataMappings>
<DxToolbarDataMapping Name="ValueName" Text="ValueName" Children="Values" Checked="IsChecked" />
<DxToolbarDataMapping Text="Value" Level="1" />
</DataMappings>
</DxToolbar>
</div>
@code {
void OnItemClicked(ToolbarItemClickEventArgs args) {
if (args.ItemName == "Align") {
((FormatItem)args.Info.Data).ChangeChecked();
}
}
}