How to get row index inside CommandClicked event handler?

Hi Great Support ,

I have a simple SFGrid , last column of this grid is custom column;

As you can see there is button every row and triggers  "CommandClickHandler"

Here is my CommandClickHandler ;

I am trying to get which row index button i have clicked . Unfortunately "GetRowIndexByPrimaryKey" is not working.

Are there any way to get row index inside "CommandClickHandler" ?


3 Replies 1 reply marked as answer

DR Dhivya Rajendran Syncfusion Team July 10, 2020 12:39 PM UTC

Hi Ahmet, 

Greeting from Syncfusion Support. 

We have validated the reported problem at our end. We confirmed “GetRowIndexByPrimaryKey method return incorrect result in Grid” as a bug and logged a defect report for the same. Thank you for taking the time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle ) and including the defect fix in our upcoming  weekly patch release which is expected to be rolled out on or before 15th July 2020.   
  
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.  


Until then we suggest you to use the below way to get the row index in command column click event. Please refer the below code example for more information. 

<SfGrid ID="Grid" @ref="Grid" DataSource="@Orders" AllowExcelExport="true"> 
    <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="false" 
                      Mode="EditMode.Normal"></GridEditSettings> 
    <GridEvents OnToolbarClick="ToolbarClick" CommandClicked="CommandClick" TValue="Order"></GridEvents> 
    <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Excel"></GridFilterSettings> 
    <GridColumns> 
        <GridColumn AllowEditing="false" AllowAdding="false" HeaderText="Manage Records" Width="150"> 
            <GridCommandColumns> 
                <GridCommandColumn Type="CommandButtonType.Edit" ButtonOption="@(new CommandButtonOptions() {IconCss="e-icons e-edit", CssClass="e-flat" })"></GridCommandColumn> 
            </GridCommandColumns> 
        </GridColumn> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        . . . . . 
   </GridColumns> 
</SfGrid> 
 
@code{ 
    public List<Order> Orders { get; set; } 
    public List<EmployeeData> Employees { get; set; } 
    SfGrid<Order> Grid { get; set; } 
 
    private void CommandClick(CommandClickEventArgs<Order> args) 
    { 
       var RowIndex = Grid.CurrentViewData.ToList().IndexOf(args.RowData); 
    } 

Regards, 
R.Dhivya  


Marked as answer

BL Blazor July 10, 2020 01:43 PM UTC

Thank you Rajendran,

It's working good! I will use this way.

Before 18.2.44 release i was using "OnRecordClick" event .
When i was clicking my row button :  "OnRecordClick" was firing (gives index of row) then "CommandClicked" was firing.

But after 18.2.44 something has changed about "OnRecordClick" event and my command button is not firing "OnRecordClick" any more, here is docs.



Best regards.



VN Vignesh Natarajan Syncfusion Team July 13, 2020 02:43 PM UTC

Hi Customer,  
 
Thanks for the update.  
 
We are glad to hear that you have resolved your query using our solution.   
 
Query: “But after 18.2.44 something has changed about "OnRecordClick" event and my command button is not firing "OnRecordClick" any more, here is docs 
 
We are able to reproduce the reported issue at our end too. We have confirmed it is a bug and logged the defect report “OnRecordClick event is not triggering while clicking the GridCommandbuttons” for the same. Thank you for taking the time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle ) and including the defect fix in our upcoming 2020 Volume 2 Service Pack release which is expected to be rolled out by end of this month (July 2020).  
 
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link. 
 
 
You can achieve your requirement using CommandClicked event of the Grid. Kindly get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan 


Loader.
Up arrow icon