Hello Jeffrey,
If the user hits Enter on any edited cell, the cell below it will open for editing. This is by design. You can tweak this behavior via the Grid state - see "Initiate Edit or Insert of an Item". However, the complete algorithm is a bit cumbersome, because it is unusual to cancel editing in one cell and go to another.
These are the additions you need to make to the KB code. Basically, you will:
<TelerikGrid @ref="@GridRef"
OnEdit="@OnGridEdit" />
@code {
private TelerikGrid<Product> GridRef { get; set; }
private bool ShouldCancelLastRowEdit { get; set; }
private bool ShouldEditFirstCell { get; set; }
private async Task AppendGridRow(string editField)
{
// ...
if (lastKey == "Enter" && editField != nameof(Product.Name))
{
ShouldCancelLastRowEdit = true;
}
}
private async Task OnGridEdit(GridCommandEventArgs args)
{
if (ShouldCancelLastRowEdit)
{
ShouldCancelLastRowEdit = false;
args.IsCancelled = true;
ShouldEditFirstCell = true;
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
// ...
}
if (ShouldEditFirstCell)
{
ShouldEditFirstCell = false;
var state = GridRef.GetState();
Product lastItem = state.OriginalEditItem = GridData.LastOrDefault();
state.EditField = nameof(Product.Name);
state.EditItem = new Product() { Id = lastItem.Id }; // cloning may be more appropriate
await GridRef.SetState(state);
}
await base.OnAfterRenderAsync(firstRender);
}
}
Regards,
Dimo
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hello Jeffrey,
Here is an example that shows how to add new Grid rows on Enter with a few lines of JavaScript and C#.
We evaluated this request and came to the conclusion that it's not suitable for a built-in feature, due to conflicts and incompatibilities with other features. Specifically, the expected behavior can be ambiguous with virtual scrolling or paging. That's why, I hope the demonstrated routine will do the job.
Regards,
Dimo
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.