Event for Toolbar Update button

Hello,


I have added the SfGrid component at my Blazor project and I have the Update button at my toolbar.

I would like to know if there is an event triggered when specifically the Update button is clicked and not any other button of the Toolbar.


If there is not such event
I would like to know how to implement it and assign it at the Update button


Here is my SfGrid component


 <SfGrid DataSource="Measurements" @ref="Grid" Toolbar="@(new List<string>() { "Add", "Update", "Cancel","Search","Delete" })" >
                    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" NewRowPosition="NewRowPosition.Bottom" Mode="EditMode.Batch">
                    </GridEditSettings>
                    <GridColumns>
                        <GridColumn Field=@nameof(Measurement.OrderID)
                                    HeaderText="Order ID"
                                    IsPrimaryKey="true"
                                    Width="120"></GridColumn>
                        <GridColumn Field=@nameof(Measurement.Name)
                                    HeaderTextAlign="TextAlign.Center"
                                    HeaderText="Name"
                                    AllowAdding="true"
                                    ValidationRules="@(new ValidationRules{ Required= true})">
                        </GridColumn>
                    </GridColumns>
                </SfGrid>


Thanks in advance!


1 Reply 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team March 21, 2022 02:06 PM UTC

Hi Amanda, 

Greetings from Syncfusion. 

Query: I would like to know if there is an event triggered when specifically the Update button is clicked and not any other button of the Toolbar. 

You can use OnToolbarClick event of the Grid to achieve your requirement. You can identify the clicked item properties to differentiate the toolbar items. Find the below code snippets and documentation for your reference. 

 
<SfGrid ID="Grid" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })" Height="315"> 
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch"></GridEditSettings> 
    <GridEvents OnToolbarClick="ToolbarClickHandler" TValue="Order"></GridEvents> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" ValidationRules="@(new ValidationRules { Required = true })" Type="ColumnType.Number" Width="120"></GridColumn> 
        . . . 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    public List<Order> Orders { get; set; } 
 
    .. .  
    public void ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args) 
    { 
        if(args.Item.Text == "Update") 
        { 
            // Here, you can customize your code. 
        } 
    } 
} 

Reference

Please let us know if you have any concerns. 

Regards, 
Rahul 


Marked as answer
Loader.
Up arrow icon