ADMIN EDIT: The issue stems from the data operations in the business logic, and it is not a bug in the component and it does not relate to WebAPI usage.
Hi there,
as a follow-up of https://feedback.telerik.com/blazor/1461176-set-specific-position-in-virtual-scrolling-mode we have implemented the suggested skip handling. But there seems an issue when the data is fetched asynchronously, specifically from an Web API.
After hours of debugging and analyzing i have narrowed it down to the following simple Blazor app showcasing the bug:
https://github.com/ViRuSTriNiTy/blazor-app-telerik-grid-skip-bug
Please clone the repo, start the application and follow the steps displayed above the grid to reproduce the bug.
The second skip followed immediatelly after the first one originates from the Telerik assembly hence i cannot investigate it further (no source code).
What are your thoughts? Is it a bug?
So lonG
Daniel
Hi Marin,
the grid is working pretty well now. Thanks again for the provided solution an insight.
So lonG
Daniel
Hi Daniel,
It is valid in the sense that it tells the grid how many records there are in total - if you know that you will immediately fire a filter operation it could serve.
The point of virtualization and the OnRead event (mostly of the OnRead event) is to NOT load all the records at once, but to only load the current page. Thus, actual paging, filtering and other operations are given to the server where the performance is better, and also less data has to travel to the client. Perhaps the following sample projects can also help you get started with server filtering too: https://github.com/telerik/blazor-ui/tree/master/grid/datasourcerequest-on-server.
Regards,
Marin Bratanov
Progress Telerik
Hi Marin,
thanks for the response.
I think i had a wrong understanding of the skip mechanism. The proposed solution works but it causes another issue. Let me explain. We have a data source with huge amount of data rows hence we use virtual scrolling to return only a portion of that data. With the proposed solution i first have to return a huge amount of items to scroll to a very large scroll index.
Is it feasible to update only the TotalCount and then set the skip value?
I really cannot return so many items only to set the skip accordingly as it will blow up the data source service.
So lonG
Daniel
Hi Daniel,
Here's what happens:
If you try to Skip a smaller number (say, 15), it would "work" because there is enough data to perform step 3 as expected. When the current data set is too small, you must ensure there is enough data to scroll that far down.
To solve this, you must update the grid data source so it has those items before scrolling to them. The key thing is that there are two distinct operations here - a filter (data source change) and a page (scroll, skip) change - so this needs two separate data requests.
Here's the changed code:
public async Task ResetSearchValueAndSetGridSkip32()
{
SearchValue = "";
// the fix - request the new grid data so the grid has enough items to scroll down 31 items
await ReadGridItems();
StateHasChanged();
// end fix
await GridSetSkip(Grid, 32);
}
and
// this is refactored to store the last data source request so you can call it from the method above
public Telerik.DataSource.DataSourceRequest LastRequest { get; set; }
protected Task ReadGridItemsHandler(GridReadEventArgs args)
{
LastRequest = args.Request;
return ReadGridItems();
}
protected async Task ReadGridItems()
{
var skip = LastRequest.Skip;
var pageSize = LastRequest.PageSize;
LastSkip = skip;
var httpClient = HttpClientFactory.CreateClient("MyHttpClient");
var response = await httpClient.GetAsync("api/values/get");
var responseContent = await response.Content.ReadAsStringAsync();
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<GridData>(responseContent);
var query = result
.Rows
.AsQueryable()
.Where(r =>
r.Kurztext != null && r.Kurztext.ToUpper().Contains(SearchValue.ToUpper()) ||
r.Langtext != null && r.Langtext.ToUpper().Contains(SearchValue.ToUpper())
);
Items = query
.OrderBy(o => o.Ordnungszahl)
.Skip(skip)
.Take(pageSize)
.ToList();
TotalCount = query.Count();
}
// end refactor
Regards,
Marin Bratanov
Progress Telerik