Declined
Last Updated: 04 Jun 2020 07:22 by Daniel
Daniel
Created on: 15 May 2020 08:28
Category: Grid
Type: Bug Report
2
Grid does not set skip correctly when fetching data from a Web API

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

 

 

5 comments
Daniel
Posted on: 04 Jun 2020 07:22

Hi Marin,

the grid is working pretty well now. Thanks again for the provided solution an insight. 

So lonG

Daniel

ADMIN
Marin Bratanov
Posted on: 26 May 2020 16:02

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Daniel
Posted on: 26 May 2020 15:51
Hi again, tested changing TotalCount only and it works! Can you confirm that this is a valid approach? So lonG Daniel
Daniel
Posted on: 26 May 2020 15:24

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

ADMIN
Marin Bratanov
Posted on: 21 May 2020 08:28

Hi Daniel,

Here's what happens:

  1. The grid data source is filtered with the first button. The grid now has a small number of items (31 in this case).
  2. The "filter" string is reset with the second button, but the grid data is still filtered - and so there are still only 31 items.
  3. The new Skip is applied and the grid tries to scroll down. There are, however, not enough items in the data for that to happen so the grid scrolls only as far as possible (TotalCount minus the PageSize which is 31 minus 10 => here's where 21 comes from for the Skip).
  4. The change of the Skip setting in the state causes the OnRead event to fire, and since the application logic now returns different data there, the grid has more items and can now scroll down to Skip=21.

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.