Is there a way to handle keyboard events in grid.

Hi

Is there anyway to capture keyboard events such as Keydown or Keypress on the grid please?

3 Replies 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team July 16, 2020 12:23 PM UTC

Hi Paul,  
 
Greetings from Syncfusion support.  
 
Query: “Is there anyway to capture keyboard events such as Keydown or Keypress on the grid please? 
 
From your query we understand that you want to capture the keyboard events in Grid component. By default, we have provided support for different events which will be triggered during a certain action in Grid. So kindly share the following detail to validate the reported query at our end.    
 
  1. Do you want to open a dialog while pressing the key by selecting a record?
  2. Or do you want to perform Edit action on pressing the enter key.
  3. Kindly share more details about your requirement.
 
Above requested details will be helpful for us to validate the reported query at our end and provide details as soon as possible.  
 
Regards, 
Vignesh Natarajan 



PS paul stanley July 18, 2020 03:33 PM UTC

Greetings.

While focused on the grid but not editing I would like to be able to press a key for example a number and that number to be inserted else where on the page.


VN Vignesh Natarajan Syncfusion Team July 20, 2020 02:08 PM UTC

Hi Paul,  
 
Thanks for the update.  
 
Query: “ I would like to be able to press a key for example a number and that number to be inserted else where on the page 
 
We have achieved your requirement using onkeyup event of Blazor. We have displayed the pressed key value in page and if it is a number we have selected a record in Grid. Refer the below code example.  
 
<h1>Pressed Key: @pressedKey</h1> 
  
<div> 
    <SfGrid @ref="Grid" @onkeyup="onkeyup" DataSource="@Orders" AllowPaging="true"> 
        <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> 
</div> 
  
@code{ 
    SfGrid<Order> Grid { getset; } 
    public List<Order> Orders { getset; } 
    public string pressedKey { getset; } 
    public async Task onkeyup(KeyboardEventArgs args) 
    { 
        pressedKey = args.Key; 
        int i = 0; 
        bool result = int.TryParse(args.Key, out i); //i now = 108 
        if (result) 
        { 
            await Grid.SelectRow(Convert.ToInt32(args.Key)); 
        } 
    } 
 
   
Kindly download the sample from below  
 
 
Refer our API documentation for your reference 
 
 
Kindly get back to us if you have further queries.   
 
Regards, 
Vignesh Natarajan 


Marked as answer
Loader.
Up arrow icon