OnActionBegin event

Hello,

I'm trying to add some logging to the grids. For example when user change page size I would like to log new selected value. At the moment ActionEventArgs does not provide any information paging action.

So if I need to log something like I mention above I must use grid reference which containts PageSettings.PageSize

Since Syncfusion.Blazor.Grids.Action.Paging is used for page size and for page selection events I cannot distinct if its a page change or page size change, hence I just want to log page size changes


In addition to that if I would like to log how users use filters how I can do that? since there is no info ActionEventArgs provide on filtering parameters


In addition to that, if I add Print toolbar button Toolbar="@(new List<string>() { "Print","Search", })" after pressing pring button none OnActionBegin or OnActionComplete is trigerred


Could you advice how this can be done?






1 Reply

VN Vignesh Natarajan Syncfusion Team December 28, 2021 10:38 AM UTC

Hi Eimantas, 
 
Thanks for contacting Syncfusion support.  
 
Query: “For example when user change page size I would like to log new selected value. && I would like to log how users use filters how I can do that?  
 
We understand you requirement and we suggest you to achieve your requirement using the below way. We have maintained a global variable to store the CurrentPageSize and based on the CurrentPageSize value, we have logged the Page size. OnActionBegin event will be trigger when certain actions like filtering, sorting, paging, searching etc. gets initiated in Grid. So we have passed limited details in event argument. We have sent CurrentPage and previous page details in the event arguments, all other values can be found from GridInstance (ref).  
 
Refer the below code example.  
 
<SfGrid @ref="Grid" DataSource="@Orders" AllowFiltering="true" AllowPaging="true"> 
    <GridPageSettings PageSizes="true"></GridPageSettings> 
    <GridEvents OnActionBegin="ActionBeginHandler" TValue="Order"></GridEvents> 
    <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{ 
    SfGrid<Order> Grid { getset; } 
  
    public List<Order> Orders { getset; } 
  
    //default value. 
    public int Current_PageSize { getset; } = 12; 
  
    public void ActionBeginHandler(ActionEventArgs<Order> Args) 
    { 
        //will be triggerd when initiating some action in pager component.  
        if (Args.RequestType == Syncfusion.Blazor.Grids.Action.Paging) 
        { 
            if (Grid.PageSettings.PageSize != Current_PageSize) 
            { 
                Current_PageSize = Grid.PageSettings.PageSize; 
                Console.WriteLine(Grid.PageSettings.PageSize.ToString()); 
                //log the page size here. 
            } 
        } 
  
        //will be triggered when initiating the iltering operation.  
        if (Args.RequestType == Syncfusion.Blazor.Grids.Action.Filtering) 
        { 
            //Args.CurrentFilteringColumn return the current filter operation requested column 
            Console.WriteLine("Column:"); 
            Console.WriteLine(Args.CurrentFilteringColumn); 
            //Args.CurrentFilterObject - return the current filter options 
        } 
    } 
 
   
Similarly we can retrieve the filter details from OnActionBegin event when RequestType is of filtering type.  Kindly refer the below sample for your reference 
 
 
Please get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan  


Loader.
Up arrow icon