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

Prevent Row Selection when GridCommandColumn button is pushed


Hi,

I am trying to prevent the row from toggling between selected and unselected when a GridCommandColumn(CommandButtonType.None) is pushed.
I am able to trigger theCommandClickEventArgs just fine, but I only seem to be able to do "args.Cancel = true" in RowSelectingEventArgs (which triggers first)
If I could detect a command click in RowSelecting (that would work) or if I could stop row selecting in CommandClickEvent that would work as well.
Any thoughts?

Thanks

3 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team July 20, 2020 04:23 PM UTC

Hi James, 
 
Greetings from Syncfusion. 
 
Query: Prevent Row Selection when GridCommandColumn button is pushed  
 
We have validated your query and you want prevent the row selection while clicking command column button. You can achieve your requirement by using OnRecordClick and RowSelecting events. In the below example, it will prevent the row selecting while we are clicking command column button and it selects the row while clicking the row(other than the command column).  
 
Find the below code snippets and sample for your reference. 
 
 
@using Syncfusion.Blazor.Grids 
 
<SfGrid DataSource="@Orders" AllowPaging="true" Height="315"> 
    <GridEvents OnRecordClick="RecordClickHandler" RowSelecting="RowSelectingHandler" CommandClicked="OnCommandClicked" TValue="Order"></GridEvents> 
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        . . . 
        <GridColumn HeaderText="Manage Records" Width="150"> 
            <GridCommandColumns> 
                <GridCommandColumn Type="CommandButtonType.None" ButtonOption="@(new CommandButtonOptions()  
{ Content = "Details", CssClass = "e-flat" })"></GridCommandColumn> 
            </GridCommandColumns> 
        </GridColumn> 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    public bool IsCommand { getset; } = false; 
    public List<Order> Orders { getset; }  //introducing bool variable 
 
    . . . 
    public void RecordClickHandler(RecordClickEventArgs<Order> args) 
    { 
        if(args.Column.HeaderText.Equals("Manage Records"))   //checked whether it is command column header text or not 
        { 
            IsCommand = true; 
        } 
        else 
        { 
            IsCommand = false; 
        } 
    } 
 
    public void OnCommandClicked(CommandClickEventArgs<Order> args) 
    { 
        // Perform required operations here 
    } 
    public void RowSelectingHandler(RowSelectingEventArgs<Order> args) 
    { 
        if (IsCommand) 
        { 
            args.Cancel = true; 
        } 
    } 
} 
 
 
 
Reference: 
 
Please get back to us if you need further assistance. 
 
Regards, 
Rahul 
 


Marked as answer

JM James Murray July 21, 2020 06:36 AM UTC

EXACTLY what i was looking for.  Thanks so much!


RN Rahul Narayanasamy Syncfusion Team July 22, 2020 05:14 AM UTC

Hi James, 
 
Thanks for the update. 
 
We are glad to hear that the provided solution was helpful to achieve your requirement. 
 
Please get back to us if you need further assistance. 
 
Regards, 
Rahul  


Loader.
Up arrow icon