Completed
Last Updated: 26 Jul 2022 08:11 by ADMIN
Nate
Created on: 25 Jul 2022 16:10
Category: ComboBox
Type: Feature Request
1
Expose a list of the available groups in the OnRead event arguments
I am using a Groupable ComboBox and I would like access to the list of the available groups so that I can create a custom group name sort order.
2 comments
ADMIN
Svetoslav Dimitrov
Posted on: 26 Jul 2022 08:11

Hello Nate,

I did some further testing and the list of the available groups is already available. Below, I have added a code snippet that provides custom sort for the Groups:

@using Telerik.DataSource.Extensions
@using Telerik.DataSource

<div class="example-box">
    <TelerikComboBox TItem="Car" TValue="int"
                     TextField="Model"
                     ValueField="Id"
                     GroupField="Make"
                     Filterable="true"
                     @bind-Value="@Value"
                     OnRead="@ReadItems">
            <ComboBoxSettings>
                <ComboBoxPopupSettings Height="200px"></ComboBoxPopupSettings>
            </ComboBoxSettings>
    </TelerikComboBox>
</div>

@code {
    int Value { get; set; }
    List<Car> SourceData { get; set; } = new List<Car> {
        new Car { Id = 1, Make = "Audi", Model="A1" },
        new Car { Id = 2, Make = "Audi", Model="A2" },
        new Car { Id = 3, Make = "Audi", Model="A3" },
        new Car { Id = 4, Make = "Audi", Model="A4" },
        new Car { Id = 5, Make = "Audi", Model="A5" },
        new Car { Id = 6, Make = "Audi", Model="A6" },
        new Car { Id = 7, Make = "BMW", Model="1" },
        new Car { Id = 8, Make = "BMW", Model="2" },
        new Car { Id = 9, Make = "BMW", Model="3" },
        new Car { Id = 10, Make = "BMW", Model="5" },
        new Car { Id = 11, Make = "Mercedes", Model="A" },
        new Car { Id = 12, Make = "Mercedes", Model="C" },
        new Car { Id = 13, Make = "Mercedes", Model="S" },
        new Car { Id = 14, Make = "Mercedes", Model="E" },
        new Car { Id = 15, Make = "Mercedes", Model="AMG" },
        new Car { Id = 16, Make = "Mercedes", Model="CLA" }
    };

    protected async Task ReadItems(ComboBoxReadEventArgs args)
    {
        await Task.Delay(200);

        var datasourceResult = SourceData.ToDataSourceResult(args.Request);

        var sortedData = datasourceResult.Data.Cast<AggregateFunctionsGroup>().ToList();

        sortedData.Sort((a, b) =>
        {
            if(a.Key.ToString() == "Audi" && b.Key.ToString() == "BMW" )
            {
                return 1;
            }
            else
            {
                return 0;
            }
        });

        args.Data = sortedData;
    }

    public class Car
    {
        public int Id { get; set; }
        public string Make { get; set; }
        public string Model { get; set; }
    }
}

That being said, I am marking this feature request as Completed.

Regards,
Svetoslav Dimitrov
Progress Telerik

The Premier Dev Conference is back! 

Coming to you live from Progress360 in-person or on your own time, DevReach for all. Register Today.


Nate
Posted on: 26 Jul 2022 02:37

Example where this would be useful: https://blazorrepl.telerik.com/cGOhGHkc37tU45rk24

Would like to show the "Common" group first, but instead the "Big" group show first because it forces alphabetical order.