Completed
Last Updated: 30 Oct 2019 14:56 by ADMIN
Release 2.3.0
Olivier
Created on: 28 Oct 2019 17:06
Category: Grid
Type: Bug Report
0
Grid does not show data until you filter, when the collection is not initialized before calling the service, and there is a delay in the data retrieval
Put the snippet in the index page

Expected: the grid has data

Actual: the grid has no data, it shows up after a data source operation like filter/group

Sample:

@using ClientApp.Shared
@inject HttpClient Http

<TelerikGrid Data=@forecasts Height="550px"
                Pageable="true" Sortable="true"
                PageSize="20" Groupable="true">
    <GridColumns>
        <GridColumn Field="Date">
            <Template>
                @((context as WeatherForecast).Date.ToString("dddd, dd MMM yyyy"))
            </Template>
        </GridColumn>
        <GridColumn Field="TemperatureC" Title="Temp. C" />
        <GridColumn Field="TemperatureF" Title="Temp. F" />
        <GridColumn Field="Summary" />
    </GridColumns>
</TelerikGrid>

@code {

    //List<WeatherForecast> forecasts { get; set; } = new List<WeatherForecast>(); // Works fine!


    List<WeatherForecast> forecasts { get; set; } //Need to sort a field to show the rows

    protected override async Task OnInitializedAsync()
    {
        //forecasts = new List<WeatherForecast>(); //this helps

        forecasts = await Http.GetJsonAsync<List<WeatherForecast>>("WeatherForecast");

        //these do not help
        //await Task.Delay(200);
        //StateHasChanged();
    }
}

1 comment
ADMIN
Marin Bratanov
Posted on: 30 Oct 2019 06:24

This is also reproducible in a server app and the issue stems from two factors:

  • delay in the data retrieval
  • the data collection not being initialized before that

Here's a repro with workarounds and explanations (the same applies to the client app as well):

 

@using ServerApp.Data

<TelerikGrid Data=@forecasts Height="550px"
             Pageable="true" Sortable="true"
             PageSize="20" Groupable="true">
    <GridColumns>
        <GridColumn Field="Date">
            <Template>
                @((context as WeatherForecast).Date.ToString("dddd, dd MMM yyyy"))
            </Template>
        </GridColumn>
        <GridColumn Field="TemperatureC" Title="Temp. C" />
        <GridColumn Field="TemperatureF" Title="Temp. F" />
        <GridColumn Field="Summary" />
    </GridColumns>
</TelerikGrid>

@code {

    List<WeatherForecast> forecasts { get; set; } = new List<WeatherForecast>(); // Works fine!


    //List<WeatherForecast> forecasts { get; set; } //Need to sort a field to show the rows

    protected override async Task OnInitializedAsync()
    {
        //forecasts = new List<WeatherForecast>(); //this helps

        await Task.Delay(2000);
        forecasts = await GetForecasts();

        //these do not help
        //await Task.Delay(200);
        //StateHasChanged();
    }

    public Task<List<WeatherForecast>> GetForecasts()
    {
        var rng = new Random();
        return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
        {
            Date = DateTime.Now.Date.AddDays(index),
            TemperatureC = rng.Next(-20, 55),
            Summary = $"summary {index}"
        }).ToList());
    }
}

 

 

Regards,
Marin Bratanov
Progress Telerik

 UI for Blazor