Skip to content

Commit 6414e7d

Browse files
984711: Updated the UG content and samples for Toolbar in DataGrid
1 parent 0c3bc23 commit 6414e7d

File tree

3 files changed

+15
-37
lines changed

3 files changed

+15
-37
lines changed

blazor/datagrid/custom-toolbar.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ The custom toolbar in the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazo
1212

1313
This is implemented by using the `Template` property, which provides extensive customization options for the toolbar. Define a custom template for the toolbar and handle toolbar item actions in the **OnClick** event.
1414

15-
The following example demonstrates how to render a custom toolbar using `Template`:
16-
1715
{% tabs %}
1816
{% highlight razor tabtitle="Index.razor" %}
1917
@using Syncfusion.Blazor.Grids
@@ -113,16 +111,14 @@ The following example demonstrates how to render a custom toolbar using `Templat
113111
{% endhighlight %}
114112
{% endtabs %}
115113

116-
{% previewsample "https://blazorplayground.syncfusion.com/embed/hjhyWChngaryhJXi?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5" %}
114+
{% previewsample "https://blazorplayground.syncfusion.com/embed/VXBUsZBuSRVoiYtS?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}
117115

118116
## Render image with text in custom Toolbar
119117

120118
Rendering an image with text in the custom toolbar of the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid helps provide context and improves visual clarity for actions.
121119

122120
To render an image with text in the custom toolbar, use the `Template` in [SfToolbar](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.SfToolbar.html).
123121

124-
The following example demonstrates how to render images and text in the Grid toolbar using `Template`:
125-
126122
{% tabs %}
127123
{% highlight razor tabtitle="Index.razor" %}
128124
@using Syncfusion.Blazor.Grids
@@ -224,9 +220,9 @@ The following example demonstrates how to render images and text in the Grid too
224220
225221
## Render SfDropDownList in Custom Toolbar
226222

227-
Rendering an **SfDropDownList** in the custom toolbar of the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid extends toolbar functionality and enables actions based on user selection.
223+
Rendering an [SfDropdownList](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.DropDowns.SfDropDownList-2.html) in the custom toolbar of the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid extends toolbar functionality and enables actions based on user selection.
228224

229-
This is achieved by using the `Template`. The example below shows how to render the **SfDropDownList** in the custom toolbar, where the toolbar template binds the [ValueChanged](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.DropDowns.SfDropDownList-2.html#Syncfusion_Blazor_DropDowns_SfDropDownList_2_ValueChanged) event to the **OnChange** method.
225+
This is achieved by using the `Template`. The example below shows how to render the `SfDropDownList` in the custom toolbar, where the toolbar template binds the [ValueChanged](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.DropDowns.SfDropDownList-2.html#Syncfusion_Blazor_DropDowns_SfDropDownList_2_ValueChanged) event to the **OnChange** method.
230226

231227
In the **OnChange** method, the selected item text determines the action. For example, if **Update** is chosen, the [EndEditAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_EndEditAsync) method exits edit mode. If **Edit** is selected, the selected record is passed to [StartEditAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_StartEditAsync) to start editing dynamically. Similarly, if **Delete** is chosen, the selected record is passed to [DeleteRecordAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_DeleteRecordAsync) to remove it from the Grid.
232228

@@ -361,8 +357,6 @@ This is implemented by using the `Template` property of the [Toolbar](https://bl
361357

362358
In the **OnSearch** method, the selected value from `SfAutoComplete` is used as the search keyword. The Grid’s [SearchAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_SearchAsync_System_String_) method filters records that match the keyword across all searchable columns.
363359

364-
The following example shows how to render `SfAutoComplete` inside the Grid toolbar and use it to perform search operations:
365-
366360
{% tabs %}
367361
{% highlight razor tabtitle="Index.razor" %}
368362

@@ -470,16 +464,14 @@ The following example shows how to render `SfAutoComplete` inside the Grid toolb
470464
{% endhighlight %}
471465
{% endtabs %}
472466

473-
{% previewsample "https://blazorplayground.syncfusion.com/embed/VDBysCBdJXXyIRKP?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5" %}
467+
{% previewsample "https://blazorplayground.syncfusion.com/embed/BthoNTLFzGxGrdMg?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}
474468

475469
## Render a component or element using the Toolbar Template
476470

477471
Rendering a component or element by using the toolbar template in the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid extends the toolbar with custom components such as buttons, dropdowns, input fields, icons, or other UI elements. Event handlers can be bound within the template to enable actions for the added components.
478472

479473
To render custom components within the toolbar, use the `Template` directive. For example, include an [SfButton](https://help.syncfusion.com/cr/blazor/syncfusion.blazor.buttons.sfbutton.html) and perform specific Grid actions based on button clicks. When the **ExcelExport** button is clicked, [ExportToExcelAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_ExportToExcelAsync_Syncfusion_Blazor_Grids_ExcelExportProperties_System_Nullable_System_Boolean__System_Object_System_Nullable_System_Boolean__) exports the Grid to Excel. When the **PdfExport** button is clicked, [ExportToPdfAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_ExportToPdfAsync_Syncfusion_Blazor_Grids_PdfExportProperties_System_Nullable_System_Boolean__System_Object_System_Nullable_System_Boolean__) exports the Grid to PDF. Likewise, when the Print button is clicked, [PrintAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_PrintAsync) is triggered to print the Grid.
480474

481-
The following example demonstrates how to render an **SfButton** in the toolbar using `Template` and perform Grid actions based on the corresponding button click:
482-
483475
{% tabs %}
484476
{% highlight razor tabtitle="Index.razor" %}
485477
@using Syncfusion.Blazor.Grids
@@ -576,4 +568,4 @@ The following example demonstrates how to render an **SfButton** in the toolbar
576568
{% endhighlight %}
577569
{% endtabs %}
578570

579-
{% previewsample "https://blazorplayground.syncfusion.com/embed/rNVysZtiBWCpVQjw?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}
571+
{% previewsample "https://blazorplayground.syncfusion.com/embed/rNVysZtiBWCpVQjw?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}

blazor/datagrid/tool-bar.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ The toolbar can be configured with built-in toolbar items or custom items using
1515
- An array of strings for built-in items
1616
- An array of [ItemModel](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.ItemModel.html#Syncfusion_Blazor_Navigations_ItemModel__ctor) objects for custom items (text, icon, id, tooltip)
1717

18-
The following example demonstrates how to configure toolbar items in the Grid:
19-
2018
{% tabs %}
2119
{% highlight razor tabtitle="Index.razor" %}
2220
@using Syncfusion.Blazor.Grids
@@ -90,9 +88,7 @@ The following example demonstrates how to configure toolbar items in the Grid:
9088

9189
Enable or disable toolbar items dynamically to control which actions are available based on application logic or user interactions.
9290

93-
Toolbar items in the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid can be enabled or disabled dynamically using the [EnableToolbarItemsAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_EnableToolbarItemsAsync_System_Collections_Generic_List_System_String__System_Boolean_) method. This provides programmatic control over the availability of specific items by their IDs. For built-in toolbar items specified with strings, the Grid generates IDs (for example, Grid_Add, Grid_Edit). For custom items created with ItemModel, set the Id property explicitly and use it when enabling or disabling items.
94-
95-
In the following example, the [Blazor Toggle Switch](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Buttons.SfSwitch-1.html) toggles toolbar item availability via a Grid method. When the switch is toggled, the [ValueChange](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Buttons.SfSwitch-1.html#Syncfusion_Blazor_Buttons_SfSwitch_1_ValueChange) event executes and updates the toolbar items. Verify that the IDs passed match the toolbar item IDs generated for the Grid in the target version.
91+
Toolbar items in the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid can be enabled or disabled dynamically using the [EnableToolbarItemsAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_EnableToolbarItemsAsync_System_Collections_Generic_List_System_String__System_Boolean_) method. This provides programmatic control over the availability of specific items by their IDs. For built-in toolbar items specified with strings, the Grid generates IDs (for example, **Grid_Add, Grid_Edit**). For custom items created with ItemModel, set the Id property explicitly and use it when enabling or disabling items.
9692

9793
{% tabs %}
9894
{% highlight razor tabtitle="Index.razor" %}
@@ -134,7 +130,7 @@ In the following example, the [Blazor Toggle Switch](https://help.syncfusion.com
134130
}
135131

136132
}
137-
133+
138134
public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
139135
{
140136
if (args.Item.Text == "Expand")
@@ -211,8 +207,6 @@ Enable or disable toolbar items based on the selected row so that actions are av
211207

212208
Use the [RowSelecting](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEvents-1.html#Syncfusion_Blazor_Grids_GridEvents_1_RowSelecting) event with the [EnableToolbarItemsAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_EnableToolbarItemsAsync_System_Collections_Generic_List_System_String__System_Boolean_) method to toggle specific items by id during selection. For built-in items, refer to the generated toolbar item IDs (for example, Grid_Add, Grid_Edit, Grid_Delete). For custom items, use the ItemModel Id value. Ensure that the IDs used match the rendered toolbar item IDs in the target version.
213209

214-
The following code example demonstrates enabling or disabling toolbar items based on the selected row data:
215-
216210
{% tabs %}
217211
{% highlight razor tabtitle="Index.razor" %}
218212

@@ -405,4 +399,4 @@ The following example demonstrates changing the background color of the `Add`, `
405399

406400
N> Refer to the [Blazor DataGrid](https://www.syncfusion.com/blazor-components/blazor-datagrid) feature tour for a broad overview. Explore the [Blazor DataGrid example](https://blazor.syncfusion.com/demos/datagrid/overview?theme=bootstrap5) to understand data presentation and manipulation.
407401

408-
N> Styling tips: when using CSS isolation, place styles in the component’s .razor.css file. To target inner elements from isolated CSS, use the ::deep selector where appropriate. Consider additional state styles (hover, active, focus-visible, disabled) and high-contrast themes to improve accessibility.
402+
N> Styling tips: when using CSS isolation, place styles in the component’s **.razor.css** file. To target inner elements from isolated CSS, use the **::deep** selector where appropriate. Consider additional state styles (hover, active, focus-visible, disabled) and high-contrast themes to improve accessibility.

blazor/datagrid/toolbar-items.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ Add them by defining the [Toolbar](https://help.syncfusion.com/cr/blazor/Syncfus
3333

3434
N> Built-in item IDs are typically prefixed with the grid ID (for example, Grid_add). Use these IDs in event handlers for robust detection.
3535

36-
The following example demonstrates how to enable built-in toolbar items such as `Print` and `Search` in the DataGrid:
37-
3836
{% tabs %}
3937
{% highlight razor tabtitle="Index.razor" %}
4038
@using Syncfusion.Blazor.Grids
@@ -111,7 +109,7 @@ The following example demonstrates how to enable built-in toolbar items such as
111109

112110
Showing only icons in the built-in toolbar items allows a compact toolbar layout.
113111

114-
To display only icons, hide the text portion of the buttons using CSS. Consider accessibility: keep an accessible name by providing TooltipText or aria-labels so screen readers still announce the action.
112+
To show only icons, hide the text part of the buttons using CSS. For accessibility, provide an accessible name by using **TooltipText** or **aria-label** so screen readers can announce the action correctly.
115113

116114
{% tabs %}
117115
{% highlight razor tabtitle="Index.razor" %}
@@ -195,9 +193,7 @@ To display only icons, hide the text portion of the buttons using CSS. Consider
195193

196194
The Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid allows customizing built-in toolbar items, including disabling default actions and executing custom logic when a button is clicked.
197195

198-
Handle the [OnToolbarClick](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEvents-1.html#Syncfusion_Blazor_Grids_GridEvents_1_OnToolbarClick) event to intercept actions. Prefer checking args.Item.Id for reliability (IDs are stable and not affected by localization), although Text is also available.
199-
200-
The following example demonstrates disabling and canceling the `Add` button functionality and showing a custom message when the `Add` button is clicked:
196+
Handle the [OnToolbarClick](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEvents-1.html#Syncfusion_Blazor_Grids_GridEvents_1_OnToolbarClick) event to intercept actions. Prefer checking **args.Item.Id** for reliability (IDs are stable and not affected by localization), although Text is also available.
201197

202198
{% tabs %}
203199
{% highlight razor tabtitle="Index.razor" %}
@@ -289,7 +285,7 @@ Adding custom toolbar items to the Syncfusion<sup style="font-size:70%">&reg;</s
289285

290286
Define custom items by setting the [Toolbar](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_Toolbar) property to a collection of [ItemModel](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.ItemModel.html#Syncfusion_Blazor_Navigations_ItemModel__ctor) objects, and handle actions in the [OnToolbarClick](https://blazor.syncfusion.com/documentation/datagrid/events#ontoolbarclick) event.
291287

292-
By default, custom toolbar items are positioned on the `left` side. Change the position using the [Align](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.ItemModel.html#Syncfusion_Blazor_Navigations_ItemModel_Align) property of ItemModel. The following example positions **Collapse All** on the `right`:
288+
By default, custom toolbar items are positioned on the **left** side. Change the position using the [Align](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.ItemModel.html#Syncfusion_Blazor_Navigations_ItemModel_Align) property of ItemModel.
293289

294290
{% tabs %}
295291
{% highlight razor tabtitle="Index.razor" %}
@@ -389,8 +385,6 @@ Combining built-in and custom items provides flexibility to create a toolbar wit
389385

390386
Define the [Toolbar](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_Toolbar) property as an array that contains both built-in item names (strings) and custom items (objects with properties such as [Text](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.ToolbarItem.html#Syncfusion_Blazor_Navigations_ToolbarItem_Text), [PrefixIcon](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.ToolbarItem.html#Syncfusion_Blazor_Navigations_ToolbarItem_PrefixIcon), and [Id](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.ToolbarItem.html#Syncfusion_Blazor_Navigations_ToolbarItem_Id)).
391387

392-
The following example demonstrates how to use both built-in and custom toolbar items in the DataGrid. Built-in items include **Add**, **Edit**, **Delete**, **Update**, and **Cancel**, and the custom item Click triggers a custom message:
393-
394388
{% tabs %}
395389
{% highlight razor tabtitle="Index.razor" %}
396390
@using Syncfusion.Blazor.Grids
@@ -484,8 +478,6 @@ Customizing the position of a custom toolbar item modifies its default placement
484478

485479
By default, custom toolbar items are aligned on the left. Modify the position by setting the [Align](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.ItemModel.html#Syncfusion_Blazor_Navigations_ItemModel_Align) property of the [ItemModel](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.ItemModel.html#Syncfusion_Blazor_Navigations_ItemModel__ctor).
486480

487-
In the following sample, the `Collapse All` item is positioned on the **right**, the `Expand All` item on the **left**, and the `Search` item in the **center**:
488-
489481
{% tabs %}
490482
{% highlight razor tabtitle="Index.razor" %}
491483
@using Syncfusion.Blazor.Grids
@@ -581,12 +573,10 @@ When creating custom toolbar items using the same text as default items (such as
581573

582574
To avoid this behavior and ensure proper functionality:
583575

584-
- Assign a unique `Id` to each custom toolbar item to distinguish it from default items.
585-
- Use the `Text`, `PrefixIcon`, and `TooltipText` properties of [ItemModel](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.ItemModel.html#Syncfusion_Blazor_Navigations_ItemModel__ctor) to define appearance.
576+
- Assign a unique **Id** to each custom toolbar item to distinguish it from default items.
577+
- Use the **Text**, **PrefixIcon**, and **TooltipText** properties of [ItemModel](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.ItemModel.html#Syncfusion_Blazor_Navigations_ItemModel__ctor) to define appearance.
586578
- Handle actions in `OnToolbarClick` using the Id (or Text, if necessary).
587579

588-
The following sample shows custom toolbar items with text matching default items. These may be disabled when `GridEditSettings` is present because they are considered default items without unique IDs.
589-
590580
{% tabs %}
591581
{% highlight razor tabtitle="Index.razor" %}
592582
@using Syncfusion.Blazor.Grids
@@ -684,8 +674,10 @@ Customize a toolbar item’s tooltip text by adding items externally and setting
684674
<GridColumn Field=@nameof(OrderData.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
685675
</GridColumns>
686676
</SfGrid>
677+
687678
@code {
688679
private SfGrid<OrderData> Grid;
680+
689681
public List<OrderData> Orders { get; set; }
690682
private List<object> ToolbarItems = new List<object>() {
691683
new ItemModel() { Text = "Excel",TooltipText="Export to Excel", PrefixIcon = "e-excelexport", Id = "Grid_excelexport"}, //Here Grid is SfGrid ID.

0 commit comments

Comments
 (0)