Accessibility in Blazor DataGrid Component has several key combinations
but what is the key to enter in cell and type data
( I know F2 is some kind edit but focus goes who knows where in grid)
I would like to edit cell with keyboard write it with enter
and move with arrow keys to move some other cell and edit that
I suppose quite simple question I just do not find answer anywhere
Hi Jukka,
Greetings from Syncfusion Support.
Query: "What key combination puts cell in edit mode(default)"
We have analyzed your query and we have already discussed about this topics detailly in our demos. Kindly refer the demos link shared.
Refer our demos : https://blazor.syncfusion.com/demos/datagrid/keyboard-navigation?theme=fluentIf
F2 button is used to make the selected record go into edit state. Using Tab key, we can navigate between the editor cells. Please get back to us if you have further queries
Regards,
Naveen Palanivel.
Hi & thanks
Naveen,
So it is just like I was afraid there is no key to enter in selected cell on normal edit mode
well I got Odatav4 and $batch working so I can live with this
But to be honest how f2 works is not quite logical as it does not keep focus on selected cell
+ modern laptops quite often do not have default function keys anymore they are replaced with
all kind of shortcuts (fn) and key is also quite unusable location on keyboard
My opinion is that maybe it would be logical in Normal edit mode Enter could be they key to go current selected cell to edit it and also when in edit mode to save cell and exit from it
Best regards,
Jukka
Hi Jukka,
Greetings from Syncfusion support.
Query: “ would be logical in Normal edit mode Enter could be they key to go current selected cell to edit it and also when in edit mode to save cell and exit from it”
By default Enter key is used to navigate the selection to the next row. So when the record is selected, press the enter key. The next row will be selected. So now we have modified the solution to make the record go into edit mode using Enter key.
Refer the below code example for your reference
|
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" @onkeydown="OnKeyDown" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height ="315"> <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings> <GridKeySettings MoveDownCell="ArrowDown" MoveUpCell="ShiftEnter,ArrowUp"></GridKeySettings> <GridColumns> <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn> <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="120"></GridColumn> <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" EditType="EditType.DatePickerEdit" Format="d" TextAlign="TextAlign.Right" Width="130" Type="ColumnType.Date"></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; } SfGrid<Order> Grid { get; set; } public async Task OnKeyDown(KeyboardEventArgs Args){ if(Args.Code == "Enter"){ var selected = await Grid.GetSelectedRecordsAsync();
if(selected.Count > 0) { await Grid.StartEditAsync(); } } } |
Kindly refer to the sample in the attachment for your reference.
Please get back to us if you have further queries.
Regards,
Vignesh Natarajan
Wow Vignesh,
There might be something wrong(different) with my grid than yours,
and your sample code made 99% all that I was hoping for.
All that is missing, atleast on my case, Enter works now quite exactly same than f2
so it moves focus to rows first editable cell not to that cell I have selected when I press Enter
( And if I use grouping on first column focus goes unseen location)
But thank you for this it is allready quite good
I think i saw some where here allready code sample how get active cell on some other case
this might just need some code to move back to cell that was active when <enter> was pressed
<Enter>
Best regards and thanks again to all of you
Jukka
Hi Jukka,
Query: “All that is missing, atleast on my case, Enter works now quite exactly same than f2 so it moves focus to rows first editable cell not to that cell I have selected when I press Enter”
We understand your requirement and we do not have direct support to achieve your requirement. But we have achieved your requirement using JSInterop and focusing the editor element using JavaScript method. Refer to the below code example.
|
@inject IJSRuntime JsRuntime
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" @onkeydown="OnKeyDown" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height ="315"> <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings> <GridKeySettings MoveDownCell="ArrowDown" MoveUpCell="ShiftEnter,ArrowUp"></GridKeySettings> <GridSelectionSettings Mode="SelectionMode.Both"></GridSelectionSettings> <GridEvents CellSelected="Selected" TValue="Order"></GridEvents> <GridColumns> <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn> <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="120"></GridColumn> <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" EditType="EditType.DatePickerEdit" Format="d" TextAlign="TextAlign.Right" Width="130" Type="ColumnType.Date"></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; } SfGrid<Order> Grid { get; set; } public double CellIndex{ get; set; } public double RowIndex { get; set; } public async Task Selected(CellSelectEventArgs<Order> Args) { CellIndex = Args.CellIndex; RowIndex = Args.RowIndex; }
public async Task OnKeyDown(KeyboardEventArgs Args) { if(Args.Code == "Enter") { await Grid.SelectRowAsync(RowIndex); var selected = await Grid.GetSelectedRecordsAsync(); if(selected.Count > 0) { await Grid.StartEditAsync(); var col = Grid.Columns[(int)CellIndex]; await JsRuntime.InvokeVoidAsync("editFocus", col.Field); } } }
[javascript.js]
function editFocus(id) { setTimeout(function () { document.getElementById(id).focus(); }, 250) } |
Kindly refer to the sample attached for your reference
Please get back to us if you have further queries.
Regards,
Vignesh Natarajan