Blazor with GridScrollMode.Virtual not maintaining scroll position when using GridEditMode.Incell or GridEditMode.Inline

1 Answer 391 Views
Grid
Bram
Top achievements
Rank 1
Iron
Iron
Bram asked on 14 Mar 2023, 11:17 AM

When a Blazor TelerikGrid component is configured to use virtual scrolling (GridScrollMode.Virtual) in combination with Inline or Incell editing, the scroll position will always jump to the top after exiting the cell edit.

This snippet shows the issue: https://blazorrepl.telerik.com/GHudPSlF1136joxn59

To replicate, scroll down a bit, edit a cell and the grid scroll position will jump to the top.

1 Answer, 1 is accepted

Sort by
1
Accepted
Dimo
Telerik team
answered on 16 Mar 2023, 09:05 AM

Hello Bram,

The scroll offset change occurs, because the Grid data is fully replaced in the OnUpdate handler.

You can update the local data collection explicitly, so that you don't have to reload the whole data.

There is also a related bug that you may want to keep an eye on.

    private async Task UpdateItem(GridCommandEventArgs args)
    {
        var updatedItem = args.Item as ProductDto;
        var originalItemIndex = GridData.FindIndex(x => x.ProductId == updatedItem.ProductId);
        GridData[originalItemIndex] = updatedItem;
        ProductService.UpdateProduct((ProductDto)args.Item);
        //await LoadData();
    }

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/.

Bram
Top achievements
Rank 1
Iron
Iron
commented on 16 Mar 2023, 09:40 AM | edited

Ok, this solves my issue.

It might be convenient (and more performant) to have the index available in the GridCommandEventArgs or maybe in the GridState.

Dimo
Telerik team
commented on 16 Mar 2023, 12:13 PM

If you aim for performance, you can store the original edit item in the OnEdit handler and then simply modify it in OnUpdate. It's not straight-forward and efficient to provide a reliable index value for each item, as it will change after data operations (sorting, filtering, paging, grouping). We will have to do a lot more work in such cases.
Bram
Top achievements
Rank 1
Iron
Iron
commented on 16 Mar 2023, 12:26 PM

I had an intermediate solution where I updated the edit item from the grid state. I'm not sure which solution I like best, depends on the use case I guess.

var updatedItem = args.Item as ProductDto;
var currentGridState = GridComponent.GetState();
currentGridState.OriginalEditItem.UpdateFromObject(updatedItem); // method to update all properties
ProductService.UpdateProduct(updatedItem);

Tags
Grid
Asked by
Bram
Top achievements
Rank 1
Iron
Iron
Answers by
Dimo
Telerik team
Share this question
or