diff --git a/Radzen.Blazor/wwwroot/Radzen.Blazor.js b/Radzen.Blazor/wwwroot/Radzen.Blazor.js index 786e68e9446..e3f92c60f0c 100644 --- a/Radzen.Blazor/wwwroot/Radzen.Blazor.js +++ b/Radzen.Blazor/wwwroot/Radzen.Blazor.js @@ -708,7 +708,7 @@ window.Radzen = { table.nextSelectedIndex = 1; } - if (key == 'ArrowLeft' || key == 'ArrowRight' || (key == 'ArrowUp' && table.nextSelectedIndex == 0 && table.parentNode.scrollTop == 0)) { + if (key == 'ArrowLeft' || key == 'ArrowRight' || (key == 'ArrowUp' && cellIndex != null && table.nextSelectedIndex == 0 && table.parentNode.scrollTop == 0)) { var highlightedCells = rows[table.nextSelectedIndex].querySelectorAll('.rz-state-focused'); if (highlightedCells.length) { for (var i = 0; i < highlightedCells.length; i++) { diff --git a/RadzenBlazorDemos/Pages/PopupDataGrid.razor b/RadzenBlazorDemos/Pages/PopupDataGrid.razor index 8c07672a3c8..96c2115cca9 100644 --- a/RadzenBlazorDemos/Pages/PopupDataGrid.razor +++ b/RadzenBlazorDemos/Pages/PopupDataGrid.razor @@ -22,12 +22,12 @@
- customerId = value = $"{args.Value}") +
- - + + @@ -44,6 +44,7 @@ string customerId; IEnumerable customers; Popup popup; + RadzenDataGrid grid; protected override async Task OnInitializedAsync() { @@ -57,53 +58,42 @@ || c.Country.ToLowerInvariant().Contains(value)); } - async Task RowSelect(Customer customer) + async Task OnRowSelect(Customer customer) { value = ""; customerId = customer.CustomerID; await popup.CloseAsync(); } - int selectedIndex = -1; + async Task OnInput(ChangeEventArgs args) + { + selectedIndex = 0; + customerId = value = $"{args.Value}"; + await grid.Reload(); + } + + int selectedIndex = 0; async Task OnKeyDown(KeyboardEventArgs args) { var items = customers; + var popupOpened = await JSRuntime.InvokeAsync("Radzen.popupOpened", "popup"); var key = args.Code != null ? args.Code : args.Key; if (!args.AltKey && (key == "ArrowDown" || key == "ArrowUp")) { - var newSelectedIndex = Math.Clamp(selectedIndex + (key == "ArrowUp" ? -1 : 1), 0, items.Count() - 1); - var shouldChange = newSelectedIndex != selectedIndex; - - if (shouldChange) - { - selectedIndex = newSelectedIndex; - await JSRuntime.InvokeAsync("Radzen.focusTableRow", "grid", key, selectedIndex - 1, null); - } - - var popupOpened = await JSRuntime.InvokeAsync("Radzen.popupOpened", "popup"); - - if (shouldChange && !popupOpened) - { - customerId = items.ElementAtOrDefault(selectedIndex)?.CustomerID; - } + var result = await JSRuntime.InvokeAsync("Radzen.focusTableRow", "grid", key, selectedIndex, null, false); + selectedIndex = result.First(); } - else if (key == "Enter" || key == "NumpadEnter") + else if (args.AltKey && key == "ArrowDown" || key == "Enter" || key == "NumpadEnter") { - var popupOpened = await JSRuntime.InvokeAsync("Radzen.popupOpened", "popup"); - - if (popupOpened) + if (popupOpened && (key == "Enter" || key == "NumpadEnter")) { customerId = items.ElementAtOrDefault(selectedIndex)?.CustomerID; } await popup.ToggleAsync(textBox.Element); } - else if (args.AltKey && key == "ArrowDown") - { - await popup.ToggleAsync(textBox.Element); - } else if (key == "Escape" || key == "Tab") { await popup.CloseAsync();