Disable default enter press functionality

Hi,

it appears that the default functionality of the DataGrid is such that when a grid has focus, and I press enter, the selected row increments to the next row.

Is there a way I can prevent this functionality please?

I have written code to capture enter key up, which I would then like to take the currently selected row and do something with it. However - upon enter press - the grid selects the next row which is not my desired functonality.

Thanks,
Jeremy

3 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team September 14, 2020 11:43 AM UTC

Hi Jeremy, 
 
Greetings from Syncfusion. 
 
Query: upon enter press - the grid selects the next row which is not my desired functonality. 
 
We have validated your query and you want to prevent the row selection while pressing Enter key. We suggest you to set the MoveDownCell value of GridKeySettings as like the below highlighted in your application to prevent next row selection when press the Enter key. 

 
<SfGrid DataSource="@Orders" @onkeyup="@KeyUp" AllowSelection="true" AllowPaging="true"> 
    <GridKeySettings MoveDownCell="ArrowDown"></GridKeySettings> 
    <GridPageSettings PageSize="5"></GridPageSettings> 
    <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; } 
 
    . . . 
    public async void KeyUp(Microsoft.AspNetCore.Components.Web.KeyboardEventArgs Args) 
    { 
        if (Args.Key == "Enter") 
        { 
            //perform your action here 
        } 
    } 
 
} 
 
 
Pleas let us know if you have any queries. 
 
Regards, 
Rahul 


Marked as answer

JE Jeremy September 15, 2020 10:12 AM UTC

Thanks for the example, that achieves exactly what I was after.

Thank you,
Jeremy


RN Rahul Narayanasamy Syncfusion Team September 16, 2020 05:20 AM UTC

Hi Jeremy, 

Thanks for the update. 

We are happy 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