Completed
Last Updated: 16 Apr 2020 08:10 by ADMIN
Release 2.11.0
Giampaolo
Created on: 15 Apr 2020 07:01
Category: Grid
Type: Bug Report
1
Infinite loop in SelectedItemsChanged when the grid is bound to a pre-filtered/sorted collection, in 2.10.0

Reproducible 

 

@page "/"

@inject NavigationManager NavMan

<TelerikGrid Data=@GridDataToShow
             SelectionMode="GridSelectionMode.Single"
             SelectedItemsChanged="@((IEnumerable<Employee> employeeList) => OnSelect(employeeList))"
             Pageable="true"
             Height="300px">
    <GridColumns>
        <GridColumn Field=@nameof(Employee.Name) />
        <GridColumn Field=@nameof(Employee.Team) Title="Team" />
    </GridColumns>
</TelerikGrid>

@code {
    public List<Employee> GridData { get; set; }
    public Employee SelectedEmployee { get; set; }
    public List<Employee> GridDataToShow // this causes the issue
    {
        get
        {
            return GridData.OrderBy(x => x.EmployeeId).ToList();
        }
    }

    protected override void OnInitialized()
    {
        GridData = new List<Employee>();
        for (int i = 0; i < 15; i++)
        {
            GridData.Add(new Employee()
            {
                EmployeeId = i,
                Name = "Employee " + i.ToString(),
                Team = "Team " + i % 3
            });
        }
    }

    protected async Task OnSelect(IEnumerable<Employee> employees)
    {
        Console.WriteLine("aaa");


        SelectedEmployee = employees.FirstOrDefault();

      //  NavMan.NavigateTo("counter");
    }

    public class Employee
    {
        public int EmployeeId { get; set; }
        public string Name { get; set; }
        public string Team { get; set; }
    }
}
1 comment
ADMIN
Marin Bratanov
Posted on: 15 Apr 2020 07:08

As a workaround, I can suggest using the grid state to set the grid sorting:

@using Telerik.DataSource;
@inject NavigationManager NavMan

<TelerikGrid Data=@GridData
             SelectionMode="GridSelectionMode.Single"
             SelectedItemsChanged="@((IEnumerable<Employee> employeeList) => OnSelect(employeeList))"
             Pageable="true"
             Height="300px"
             OnStateInit="@((GridStateEventArgs<Employee> args) => OnStateInitHandler(args))">
    <GridColumns>
        <GridColumn Field=@nameof(Employee.Name) />
        <GridColumn Field=@nameof(Employee.Team) Title="Team" />
    </GridColumns>
</TelerikGrid>

@code {
    public List<Employee> GridData { get; set; }
    public Employee SelectedEmployee { get; set; }

    async Task OnStateInitHandler(GridStateEventArgs<Employee> args)
    {
        GridState<Employee> desiredState = new GridState<Employee>()
        {
            SortDescriptors = new List<SortDescriptor>()
            {
                new SortDescriptor { Member = "EmployeeId", SortDirection = ListSortDirection.Descending }
            }
        };
        args.GridState = desiredState;
    }

    protected override void OnInitialized()
    {
        GridData = new List<Employee>();
        for (int i = 0; i < 15; i++)
        {
            GridData.Add(new Employee()
            {
                EmployeeId = i,
                Name = "Employee " + i.ToString(),
                Team = "Team " + i % 3
            });
        }
    }

    protected async Task OnSelect(IEnumerable<Employee> employees)
    {
        SelectedEmployee = employees.FirstOrDefault();

        NavMan.NavigateTo("counter");
    }

    public class Employee
    {
        public int EmployeeId { get; set; }
        public string Name { get; set; }
        public string Team { get; set; }
    }
}

 

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.