Articles in this section

How to enhance virtual scrolling functionalities in Blazor MultiSelect Dropdown?

When implementing virtual scrolling in Blazor MultiSelect Dropdown, it is essential to ensure that the scroller is enabled to allow users to scroll through a large list of items. This article addresses a common issue where virtual scrolling does not function as expected due to specific settings.

Problem Description

Virtual scrolling may not work if the dropdown’s PopupHeight and the number of items fetched by the Query are not configured correctly. For instance, if the PopupHeight is set to 350px and the Query is set to retrieve only 6 items, the scroller will not appear, preventing virtual scrolling.

Solutions

To enable virtual scrolling, you have two options:

  1. Increase the Query take value to a higher number, such as 15 items, which will allow the scroller to appear given the PopupHeight of 350px.
<SfMultiSelect TValue="string[]" TItem="Record" Placeholder="Select an item" DataSource="@Records" Query="@LocalDataQuery" PopupHeight="350px" EnableVirtualization="true">
    <MultiSelectFieldSettings Text="Text" Value="ID"></MultiSelectFieldSettings>
</SfMultiSelect>

@code {
    public Query LocalDataQuery = new Query().Take(15);
    public class Record
    {
        public string ID { get; set; }
        public string Text { get; set; }
    }
    public List<Record> Records { get; set; }
    protected override void OnInitialized()
    {
        this.Records = Enumerable.Range(1, 250).Select(i => new Record()
            {
                ID = i.ToString(),
                Text = "Item " + i,
            }).ToList();
    }
}
  1. Decrease the PopupHeight to a smaller value, like 150px, if you wish to maintain the Query take value at 6 items.

<SfMultiSelect TValue="string[]" TItem="Record" Placeholder="Select an item" DataSource="@Records" Query="@LocalDataQuery" PopupHeight="150px" EnableVirtualization="true">
    <MultiSelectFieldSettings Text="Text" Value="ID"></MultiSelectFieldSettings>
</SfMultiSelect>

@code {
    public Query LocalDataQuery = new Query().Take(6);
    public class Record
    {
        public string ID { get; set; }
        public string Text { get; set; }
    }
    public List<Record> Records { get; set; }
    protected override void OnInitialized()
    {
        this.Records = Enumerable.Range(1, 250).Select(i => new Record()
            {
                ID = i.ToString(),
                Text = "Item " + i,
            }).ToList();
    }
}

By adjusting either the Query take value or the PopupHeight, you can ensure that virtual scrolling is enabled and functioning correctly in your dropdown list.

References:

Conclusion

We hope you enjoyed learning about how to enhance virtual scrolling functionalities in Blazor MultiSelect Dropdown.

You can refer to our Blazor MultiSelect Dropdown feature tour page to know about its other groundbreaking features, documentation, and how to quickly get started with configuration specifications. You can also explore our Blazor MultiSelect Dropdown example to understand how to create and manipulate data.

For current customers, our Blazor components are available on the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to evaluate our Blazor MultiSelect Dropdown and other Blazor components.
If you have any questions or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied