Integrate Searching,multiselect and Grouping in Same Telerik Multi Select

0 Answers 29 Views
MultiSelect
Anup
Top achievements
Rank 1
Anup asked on 24 Jan 2024, 07:34 AM

Hello,

I am looking to incorporate search functionality, multiselect, and grouping in Telerik MultiSelect. Additionally, I need to make API calls for every character entered during searching. Although the OnRead parameter in TelerikMultiSelect seems to provide these arguments, I have encountered difficulty achieving grouping in Telerik MultiSelect using this parameter.

Is there a way to obtain the SearchText inside a function whenever the user is typing, allowing me to make API calls? Alternatively, can I utilize the OnRead parameter in TelerikMultiSelect to achieve grouping, searching, and multiselect simultaneously?

I have managed to retrieve the search text from MultiSelectReadEventArgs args using OnRead, as shown below:

"dynamic item = args.Request.Filters.FirstOrDefault();
var searchText = (string)item.Value; "

The code for TelerikMultiSelect is as follows:

<TelerikMultiSelect Data="@Data"
                 @bind-Value="@SelectedProducts"
                 GroupField="Category.CategoryName"
                 TextField="ProductName"
                 ValueField="ProductId"
                 Placeholder="Select a product">
</TelerikMultiSelect>

@code {
    public IEnumerable<Product> Data { get; set; }
    public List<int> SelectedProducts { get; set; } = new List<int>();

    protected override void OnInitialized()
    {
        List<Product> products = new List<Product>();
        for (int i = 0; i < 20; i++)
        {
            products.Add(new Product()
            {
                ProductId = i,
                ProductName = $"Product {i}",
                Category = new Category() { CategoryId = i % 5, CategoryName = $"Category {i % 5}" }
            });
        }

        Data = products;

        base.OnInitialized();
    }

    public class Product
    {
        public int ProductId { get; set; }
        public string ProductName { get; set; }
        public Category Category { get; set; }
    }

    public class Category
    {
        public int CategoryId { get; set; }
        public string CategoryName { get; set; }
    }
}

No answers yet. Maybe you can help?

Tags
MultiSelect
Asked by
Anup
Top achievements
Rank 1
Share this question
or