Hello,
When GridSelectionSettings.Mode = SelectionMode.Batch and AllowEditing=true and you press the Tab key in the last cell in a row and that cell value is valid, then focus moves to the first cell in the next row.
However, when GridSelectionSettings.Mode = SelectionMode.Batch and you press the Tab key in the last cell in a row, the focus moves to the next tab stop control on the form rather than the next row.
How, can I get the grid to move focus to the next row (if one exists) rather than the next tab stop when SectionMode.Row is configured?
Thanks,
Chuck
Hi Renjith,
Thank you for the quick reply and my apologies, I had a typo in my case above and wasn't entirely clear. My example should have said
GredEditSettings.Mode = SelectionMode.Batch for the first and
SelectionMode.Batch.Row for the second.
In any case, here are the exact repro steps. For the case where the grid behaves as expected, use your batch editing example Blazor DataGrid Batch Editing Example - Syncfusion Demos
I would expect that the row should have been saved and the focus should be moved to the next row.
Thanks,
Chuck
Hi Renjith,
Thank you for your reply. However, the behaviour in is inconsistent and provides for a confusing user experience.
With EditMode.Batch, tabbing from the last cell saves that cell and moves the focus to the first cell of the next row in the grid.
Whereas with EditMode.Normal, tabbing from the last cell navigates away from the grid component altogether.
At a minimum I would expect the tab key to wrap around to the first cell in the edited row so that the user can continue tabbing around the row until they press Enter or click Save.
Is there a way I can achieve this by customising the grid behaviour?
Thanks,
Chuck
|
<SfGrid @ref="GridInstance" DataSource="@Orders" ...>
...
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" ... Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" ValidationRules="@(new ValidationRules{ Required=true})" Width="120">
<EditTemplate>
<SfTextBox @ref="CustomerIDTextBox" ID="CustomerID" Placeholder="CustomerID Value" @bind-Value="@((context as Order).CustomerID)"></SfTextBox>
</EditTemplate>
</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" EditType="EditType.NumericEdit" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.ShipCountry) HeaderText="Ship Country" EditType="EditType.DropDownEdit" Width="150">
<EditTemplate>
<div @onkeydown="@KeyDownHandler" @onkeydown:preventDefault="true">
<SfDropDownList ID="ShipCountry" TItem="Order" TValue="string" @bind-Value="@((context as Order).ShipCountry)" DataSource="@Orders">
<DropDownListFieldSettings Value="ShipCountry" Text="ShipCountry"></DropDownListFieldSettings>
</SfDropDownList>
</div>
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid>
SfGrid<Order> GridInstance;
SfTextBox CustomerIDTextBox;
public async void KeyDownHandler(KeyboardEventArgs args)
{
if(args.Key == "Tab")
{
//apply focusing for the first cell when tab out of last editable cell
await CustomerIDTextBox.FocusAsync();
}
}
|
Hi Renjith,
Thank you for the solution above. This is working well. However, upon testing this approach we have concluded it would be more intuitive if, upon pressing Tab in the last column, that the row would be saved (via EndEditAsync) and focus moved to the first column of the next row.
Using your example code, I have tried to achieve this by modifying the KeyDownHandler as follows:
public async void KeyDownHandler(KeyboardEventArgs args)
{
if(args.Key == "Tab")
{
//apply focusing for the first cell when tab out of last editable cell
await DemoGrid.CloseEditAsync();
await DemoGrid.SelectRowAsync(3); //Testing setting focus to row 3 for now. If we can get this to work we'll need to dynamically determine the correct row number to select
await DemoGrid.FocusAsync();
}
}
This visually appears to select row 3 as it is highlighted and focus is set to the grid as expected. However, upon pressing Tab the focus cell and row jump to the first row in the grid.
How can I programmatically set the correct row and cell in KeyDownHandler so that when the user next presses tab they remain in the correct row?
Thanks,
Chuck
Hi Chuck,
We are checking the reported scenario from our side. We will update you further details within two business days.
Until then we appreciate your patience.
Regards,
Renjith R
Hi Chuck,
We could achieve this requirement by selecting a row based on index using SelectRowAsync method and calling the StartEditAsync method. But currently, we are facing difficulties in applying this solution. Currently, the last focused row is getting edited when calling the method, irrespective of the row selected in grid.
We have considered this a defect and this has been fixed internally, the fix is expected to be rolled out by the mid of April 2022. We will update you the suggestion for this requirement once the release is rolled out. Until then we appreciate your patience.
Regards,
Renjith R
Hi Chuck,
We have prepared a sample based on this requirement by using the suggestion from our previous update. Please download and refer the sample attached in this ticket.
We have used EditTemplate for the last column and bind @onkeydown event. In this @onkeydown event we have programmatically perform save action by calling EndEditAsync method. Now in OnActionComplete event handler we have fetched the row index and selected the corresponding row using SelectRowAsync method and based on selected index, we have called StartEditAsync to perform start edit action on the selected row. Please refer the codes below,
|
<GridEvents OnActionComplete="OnActionComplete" RowSelected="RowSelected" TValue="Order"></GridEvents>
@*Use EditTemplate for last column*@ <GridColumn Field=@nameof(Order.ShipCountry) HeaderText="Ship Country" EditType="EditType.DropDownEdit" Width="150"> <EditTemplate> <div @onkeydown="@KeyDownHandler" @onkeydown:preventDefault="true"> <SfDropDownList ID="ShipCountry" TItem="Order" TValue="string" @bind-Value="@((context as Order).ShipCountry)" DataSource="@Orders"> <DropDownListFieldSettings Value="ShipCountry" Text="ShipCountry"></DropDownListFieldSettings> </SfDropDownList> </div> </EditTemplate> </GridColumn>
public double RowIndex { get; set; } public async void KeyDownHandler(KeyboardEventArgs args) { if(args.Key == "Tab") { //call the EndEditAsync when tab the last cell await GridInstance.EndEditAsync(); } } public bool flag = false; public async Task OnActionComplete(ActionEventArgs<Order> args) { if (args.RequestType.Equals(Action.Save)) { //Get rowindex of current cell based on RequestType as save and increment by 1 flag = true; RowIndex = await GridInstance.GetRowIndexByPrimaryKeyAsync(args.Data.OrderID) + 1; } } public async Task RowSelected(RowSelectEventArgs<Order> args) { if (flag) { //select row based on calculated index flag = false; await GridInstance.SelectRowAsync(RowIndex); } if(args.RowIndex == RowIndex) { //edit the selected row await GridInstance.StartEditAsync(); } }
|
Please get back to us if you need further assistance.
Regards,
Renjith R