We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

OnActionBegin not firing on any edit action

I have the following Blazor page (modified from Grid Sample) 


@page "/"


<SfGrid DataSource="@Orders" AllowPaging="true" AllowSorting="true" AllowFiltering="true" AllowGrouping="true">

    <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Excel"></GridFilterSettings>

    <GridPageSettings PageSize="5"></GridPageSettings>

    <GridEditSettings

        AllowAdding="true"

        AllowEditing="true"

        AllowDeleting="true"

        ShowDeleteConfirmDialog="true"

        NewRowPosition="NewRowPosition.Bottom"

        Mode="EditMode.Dialog"/>

    <GridColumns>

        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>

        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>

        <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>

        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>

    </GridColumns>

</SfGrid>


@code{

    public List<Order> Orders { get; set; }


    protected override void OnInitialized()

    {

        Orders = Enumerable.Range(1, 75).Select(x => new Order()

        {

            OrderID = 1000 + x,

            CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],

            Freight = 2.1 * x,

            OrderDate = DateTime.Now.AddDays(-x),

        }).ToList();

    }


    public class Order {

        public int? OrderID { get; set; }

        public string CustomerID { get; set; }

        public DateTime? OrderDate { get; set; }

        public double? Freight { get; set; }

    }

    public void OnActionBegin(ActionEventArgs<Order> args)

    {

        if (args.RequestType.ToString() == "FilterChoiceRequest")

        {

            args.FilterChoiceCount = 2; //here, you can override the default take count of the filter records

        }

    }

}


When I run it and Edit, Add or Delete a row and click Save the OnActionBegin event does not fire.


Am I doing something wrong?



4 Replies 1 reply marked as answer

DA Development at deskcoach April 20, 2023 01:39 AM UTC

I've since worked out that I have to add the following lines to the sfGrid declaration:

<GridEvents OnActionComplete="@ActionCompletedHandler"

            OnActionBegin="@ActionBeginHandler"

            TValue="Organisation"></GridEvents>


It appears to need both as Add and Update use the "OnActionComplete" and Delete uses the "OnActionBegin"


It is really weird and counterintuitive. Also hard to find documentation on it. 



BL Balamurugan Lakshmanan Syncfusion Team April 20, 2023 09:55 AM UTC

Hi Kerry,


Greeting from Syncfusion Support.


After reviewing your information, we have identified that the issue is due to the missing definition of the GridEvents and PrimaryKeyColumn. We would like to inform you that primary key is necessary to perform all the CRUD operations. To define the primary key, set IsPrimaryKey to true in a particular column whose value is unique. We modify the sample as per your requirement. Kindly refer the attachment and UG documentation for your reference.


https://blazor.syncfusion.com/documentation/datagrid/events#onactionbegin

https://blazor.syncfusion.com/documentation/datagrid/editing#performing-crud-operation-by-using-separate-toolbar


Please get back to us if you have further queries.


Regards,

Bala.


Marked as answer

DA Development at deskcoach April 20, 2023 11:51 PM UTC

Thanks for the reply. It is solved now.



BL Balamurugan Lakshmanan Syncfusion Team April 21, 2023 03:26 AM UTC

Hi Kerry,

 

Thanks for your update.

 

We are glad to hear that you have resolved your query using our solution. Please get back to us if you have further queries.

 

Regards,

Bala.


Loader.
Up arrow icon