Duplicated
Last Updated: 03 May 2024 06:32 by ADMIN
Zhi Hong
Created on: 30 Apr 2024 09:28
Category: Grid
Type: Bug Report
1
Grid puts the third grouped column as second in the group panel

When the user drags a third column to the Grid Group Panel, it ends up being second, instead of last. It looks like each new column is inserted at index 1, instead of appended last (when this is the user's intent).

@using Telerik.DataSource

<p>Group by a third column, so that it should come last in the Group Panel:</p>

<TelerikGrid @ref="@GridRef"
             Data="@GridData"
             Pageable="true"
             Sortable="true"
             Groupable="true"
             FilterMode="GridFilterMode.FilterRow"
             OnStateInit="@( (GridStateEventArgs<Employee> args) => OnGridStateInit(args) )"
             OnStateChanged="@( (GridStateEventArgs<Employee> args) => OnGridStateChanged(args) )">
    <GridColumns>
        <GridColumn Field="@nameof(Employee.Name)" />
        <GridColumn Field="@nameof(Employee.Team)" />
        <GridColumn Field="@nameof(Employee.Salary)" />
        <GridColumn Field="@nameof(Employee.OnVacation)" />
    </GridColumns>
</TelerikGrid>

@code {
    private TelerikGrid<Employee>? GridRef { get; set; }

    private List<Employee> GridData { get; set; } = new();

    private void OnGridStateInit(GridStateEventArgs<Employee> args)
    {
        args.GridState.GroupDescriptors = new List<GroupDescriptor>();

        args.GridState.GroupDescriptors.Add(new GroupDescriptor()
        {
            Member = nameof(Employee.Team),
            MemberType = typeof(string)
        });

        args.GridState.GroupDescriptors.Add(new GroupDescriptor()
        {
            Member = nameof(Employee.OnVacation),
            MemberType = typeof(bool)
        });
    }

    private async Task OnGridStateChanged(GridStateEventArgs<Employee> args)
    {
        if (args.PropertyName == "GroupDescriptors" && args.GridState.GroupDescriptors.Count > 2 && GridRef != null)
        {
            var secondGroupDescriptor = args.GridState.GroupDescriptors.ElementAt(1);

            args.GridState.GroupDescriptors.Remove(secondGroupDescriptor);
            args.GridState.GroupDescriptors.Add(secondGroupDescriptor);

            await GridRef.SetStateAsync(args.GridState);
        }
    }

    protected override void OnInitialized()
    {
        var rnd = new Random();

        for (int i = 1; i <= 20; i++)
        {
            GridData.Add(new Employee()
            {
                Id = i,
                Name = "Name " + i,
                Team = "Team " + (i % 4 + 1),
                Salary = (decimal)rnd.Next(1000, 3000),
                OnVacation = i % 3 == 0
            });
        }
    }

    public class Employee
    {
        public int Id { get; set; }
        public string Name { get; set; } = string.Empty;
        public string Team { get; set; } = string.Empty;
        public decimal Salary { get; set; }
        public bool OnVacation { get; set; }
    }
}

Duplicated
This item is a duplicate of an already existing item. You can find the original item here:
1 comment
ADMIN
Stamo Gochev
Posted on: 03 May 2024 06:32

Hi Zhi Hong,

The issue has already been logged in the Feedback Portal:

https://feedback.telerik.com/blazor/1639920

and a bug fix has been scheduled for the upcoming 2024 Q2 (in May). 

When the release is out, you can re-check whether the fix works as expected.

Regards,
Stamo Gochev
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!