Skip to content

Commit ca36785

Browse files
984711: Updated the UG content and samples for Toolbar in DataGrid
1 parent e1969cb commit ca36785

File tree

3 files changed

+135
-114
lines changed

3 files changed

+135
-114
lines changed

blazor/datagrid/custom-toolbar.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
22
layout: post
33
title: Custom Toolbar Items in Blazor DataGrid Component | Syncfusion
4-
description: Checkout and learn here all about Custom Toolbar Items in Syncfusion Blazor DataGrid component and much more details.
4+
description: Learn how to create and use custom toolbar items in the Syncfusion Blazor DataGrid, including templates, images with text, dropdowns, autocomplete, and export actions.
55
platform: Blazor
66
control: DataGrid
77
documentation: ug
88
---
99
# Custom toolbar in Blazor DataGrid
1010

11-
Custom toolbar in Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid allows you to create a distinctive toolbar layout, style, and functionality that aligns with the specific needs of your application, providing a personalized experience within the Grid.
11+
The custom toolbar in the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid enables a distinctive toolbar layout, style, and behavior tailored to application requirements, delivering a personalized Grid experience.
1212

13-
This can be achieved by utilizing the `Template` property, which offers extensive customization options for the Toolbar. You can define a custom Template for the Toolbar and handle the actions of the ToolbarItems in the **OnClick** event.
13+
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 the custom Toolbar using `Template`:
15+
The following example demonstrates how to render a custom toolbar using `Template`:
1616

1717
{% tabs %}
1818
{% highlight razor tabtitle="Index.razor" %}
@@ -117,11 +117,11 @@ The following example demonstrates, how to render the custom Toolbar using `Temp
117117

118118
## Render image with text in custom Toolbar
119119

120-
Render an image with text in custom Toolbar in Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid allows easily render an image along with text in the Toolbar of the Grid. This feature enhances the visual presentation of the Grid, providing additional context and improving the overall experience.
120+
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.
121121

122-
To render an image with text in Custom Toolbar, you can utilize the Template in [SfToolbar](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.SfToolbar.html) in your code.
122+
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).
123123

124-
The following example demonstrates how to render an image in the Toolbar of the Grid using `Template`:
124+
The following example demonstrates how to render images and text in the Grid toolbar using `Template`:
125125

126126
{% tabs %}
127127
{% highlight razor tabtitle="Index.razor" %}
@@ -160,13 +160,13 @@ The following example demonstrates how to render an image in the Toolbar of the
160160
{
161161
Orders = OrderData.GetAllRecords();
162162
}
163-
public void AddButton()
163+
public async Task AddButton()
164164
{
165-
this.Grid.AddRecordAsync();
165+
await this.Grid.AddRecordAsync();
166166
}
167-
public void DeleteButton()
167+
public async Task DeleteButton()
168168
{
169-
this.Grid.DeleteRecordAsync();
169+
await this.Grid.DeleteRecordAsync();
170170
}
171171
}
172172
<style>
@@ -220,15 +220,15 @@ The following example demonstrates how to render an image in the Toolbar of the
220220
{% endhighlight %}
221221
{% endtabs %}
222222

223-
> You can further customize the styles and layout of the image and text in the Custom Toolbar to suit your specific design requirements.
223+
> The styles and layout of the image and text in the custom toolbar can be further customized to meet specific design requirements. For better accessibility, include alt text on images.
224224
225225
## Render SfDropDownList in Custom Toolbar
226226

227-
Render **SfDropDownList** in Custom Toolbar in Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid enables you to extend the functionality of the Custom Toolbar by incorporating a [SfDropDownList](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.DropDowns.SfDropDownList-2.html), allowing you to perform various actions within the Grid based on their selections.
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.
228228

229-
This can be achieved by utilizing the `Template`. The example below demonstrates how to render the **SfDropDownList** in the Custom Toolbar, where the Toolbar Template includes the its [ValueChanged](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.DropDowns.SfDropDownList-2.html#Syncfusion_Blazor_DropDowns_SfDropDownList_2_ValueChanged) event is bound to the **OnChange** method.
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.
230230

231-
In the **OnChange** method, the text of the selected item is checked to determine the appropriate 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 is called to exit the edit mode. If **Edit** is selected, the selected record is passed to the [StartEditAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_StartEditAsync) method to initiate the edit mode dynamically. Similarly, if **Delete** is picked, the selected record is passed to the [DeleteRecordAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_DeleteRecordAsync) method to remove it from the Grid.
231+
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.
232232

233233
{% tabs %}
234234
{% highlight razor tabtitle="Index.razor" %}
@@ -278,32 +278,32 @@ In the **OnChange** method, the text of the selected item is checked to determin
278278
{
279279
Orders = OrderData.GetAllRecords();
280280
}
281-
public void AddButton()
281+
public async Task AddButton()
282282
{
283-
this.Grid.AddRecordAsync();
283+
await this.Grid.AddRecordAsync();
284284
}
285-
public void DeleteButton()
285+
public async Task DeleteButton()
286286
{
287-
this.Grid.DeleteRecordAsync();
287+
await this.Grid.DeleteRecordAsync();
288288
}
289-
public void OnChange(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, Select> args)
289+
public async Task OnChange(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, Select> args)
290290
{
291291
var selectedRow = this.Grid.GetSelectedRecordsAsync();
292292
if (args.ItemData.text == "Edit")
293293
{
294-
this.Grid.StartEditAsync();
294+
await this.Grid.StartEditAsync();
295295
}
296296
if (args.ItemData.text == "Delete")
297297
{
298-
this.Grid.DeleteRecordAsync();
298+
await this.Grid.DeleteRecordAsync();
299299
}
300300
if (args.Value == "Update")
301301
{
302-
this.Grid.EndEditAsync();
302+
await this.Grid.EndEditAsync();
303303
}
304304
this.Dropdown.Placeholder = args.ItemData.text;
305-
306305
}
306+
307307
}
308308
{% endhighlight %}
309309
{% highlight c# tabtitle="OrderData.cs" %}
@@ -351,17 +351,17 @@ In the **OnChange** method, the text of the selected item is checked to determin
351351
{% endhighlight %}
352352
{% endtabs %}
353353

354-
{% previewsample "https://blazorplayground.syncfusion.com/embed/LDVgWDUiLWIJdsVg?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}
354+
{% previewsample "https://blazorplayground.syncfusion.com/embed/BjrSMjjihtPwLWfl?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}
355355

356356
## Render SfAutoComplete in custom toolbar
357357

358-
Rendering the [SfAutoComplete](https://blazor.syncfusion.com/documentation/autocomplete/getting-started-with-web-app) in the custom toolbar of the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid allows you to enhance the Grid's usability by enabling dynamic search operations based on input.
358+
Rendering the [SfAutoComplete](https://blazor.syncfusion.com/documentation/autocomplete/getting-started-with-web-app) in the custom toolbar of the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid enhances usability by enabling dynamic search based on user input.
359359

360-
This can be achieved by utilizing the `Template` property of the [Toolbar](https://blazor.syncfusion.com/documentation/toolbar/getting-started-webapp). The example below demonstrates how to render the `SfAutoComplete` within the custom toolbar. The [ValueChange](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.DropDowns.AutoCompleteEvents-2.html#Syncfusion_Blazor_DropDowns_AutoCompleteEvents_2_ValueChange) event of the `SfAutoComplete` is bound to the **OnSearch** method, which performs a search operation on the Grid based on the selected input.
360+
This is implemented by using the `Template` property of the [Toolbar](https://blazor.syncfusion.com/documentation/toolbar/getting-started-webapp). The example below renders the `SfAutoComplete` within the custom toolbar. The [ValueChange](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.DropDowns.AutoCompleteEvents-2.html#Syncfusion_Blazor_DropDowns_AutoCompleteEvents_2_ValueChange) event of `SfAutoComplete` is bound to the **OnSearch** method, which searches the Grid based on the selected input.
361361

362-
In the **OnSearch** method, the selected value from the `SfAutoComplete` is used as a 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 is called to filter records matching the keyword across all searchable columns.
362+
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.
363363

364-
The following example demonstrates how to render the `SfAutoComplete` inside the Grid's toolbar and use it to perform search operations:
364+
The following example shows how to render `SfAutoComplete` inside the Grid toolbar and use it to perform search operations:
365365

366366
{% tabs %}
367367
{% highlight razor tabtitle="Index.razor" %}
@@ -474,11 +474,11 @@ The following example demonstrates how to render the `SfAutoComplete` inside the
474474

475475
## Render a component or element using the Toolbar Template
476476

477-
Rendering a component or element using the Toolbar Template in the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid allows you to extend the capabilities of the Grid Toolbar by incorporating custom components or elements. This provides flexibility to enhance the Toolbar with custom buttons, dropdowns, input fields, icons, or any other desired UI elements. You can bind event handlers or handle interactions within the Template to enable specific actions or behaviors associated with the added components or elements.
477+
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.
478478

479-
To render custom components or elements within the Toolbar, use the `Template` directive. This allows you to include other components, such as a [SfButton](https://help.syncfusion.com/cr/blazor/syncfusion.blazor.buttons.sfbutton.html), and perform specific Grid actions based on the button click. For example, when the **ExcelExport** button is clicked, the [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__) method is called to export the Grid to Excel. Similarly, when the **PdfExport** button is clicked, the [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__) method is called to export the Grid to PDF format.Likewise, when the Print button is clicked, the [PrintAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_PrintAsync) method will triggered to print the Grid.
479+
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.
480480

481-
The following example demonstrates how to render a **SfButton** in the Toolbar using `Template` and perform Grid action based on the respected button click:
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:
482482

483483
{% tabs %}
484484
{% highlight razor tabtitle="Index.razor" %}
@@ -515,17 +515,17 @@ The following example demonstrates how to render a **SfButton** in the Toolbar u
515515
{
516516
Orders = OrderData.GetAllRecords();
517517
}
518-
public void ExcelExport()
518+
public async Task ExcelExport()
519519
{
520-
this.Grid.ExportToExcelAsync();
520+
await this.Grid.ExportToExcelAsync();
521521
}
522-
public void PdfExport()
522+
public async Task PdfExport()
523523
{
524-
this.Grid.ExportToPdfAsync();
524+
await this.Grid.ExportToPdfAsync();
525525
}
526-
public void Print()
526+
public async Task Print()
527527
{
528-
this.Grid.PrintAsync();
528+
await this.Grid.PrintAsync();
529529
}
530530
}
531531
{% endhighlight %}
@@ -576,4 +576,4 @@ The following example demonstrates how to render a **SfButton** in the Toolbar u
576576
{% endhighlight %}
577577
{% endtabs %}
578578

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

0 commit comments

Comments
 (0)