<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged syncfusion</title>
<link>https://coderlegion.com/tag/syncfusion</link>
<description>Powered by Question2Answer</description>
<item>
<title>Creating a Syncfusion MultiSelect Component with Two-Way Binding in Blazor</title>
<link>https://coderlegion.com/4311/creating-a-syncfusion-multiselect-component-with-two-way-binding-in-blazor</link>
<description>&lt;p&gt;In this example, we build a reusable Blazor component using Syncfusion’s SfMultiSelect that supports:&lt;/p&gt;
&lt;p&gt;Dynamic option filtering based on a Picklist type (e.g., Color, Unit)&lt;/p&gt;
&lt;p&gt;Two-way data binding with a parent component&lt;/p&gt;
&lt;p&gt;Internal state management to avoid unnecessary updates&lt;/p&gt;
&lt;p&gt; Why This Pattern?&lt;/p&gt;
&lt;p&gt;Often in enterprise forms, you need a dynamic dropdown that updates based on a type and preselects values passed from a parent. This setup ensures:&lt;/p&gt;
&lt;p&gt;Clean encapsulation&lt;/p&gt;
&lt;p&gt;Correct @bind support&lt;/p&gt;
&lt;p&gt;Lightweight rendering&lt;/p&gt;
&lt;p&gt;✅ Component Markup&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;SfMultiSelect TValue=&quot;List&amp;lt;PicklistSetDto&amp;gt;&quot;
               TItem=&quot;PicklistSetDto&quot;
               Placeholder=&quot;@Label&quot;
               DataSource=&quot;@Options&quot;
               @bind-Value=&quot;InternalSelectedValues&quot;
               Mode=&quot;VisualMode.Box&quot;
               AllowFiltering=&quot;true&quot;
               FilterType=&quot;FilterType.Contains&quot;
               PopupHeight=&quot;300px&quot;&amp;gt;
    &amp;lt;MultiSelectFieldSettings Text=&quot;Text&quot; Value=&quot;Value&quot; /&amp;gt;
&amp;lt;/SfMultiSelect&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; Component Logic&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@code {
    [Parameter]
    public string Label { get; set; } = &quot;Select Options&quot;;

    [Parameter]
    public Picklist Name { get; set; }

    [Parameter]
    public IEnumerable&amp;lt;PicklistSetDto&amp;gt; SelectedValues { get; set; } = new List&amp;lt;PicklistSetDto&amp;gt;();

    [Parameter]
    public EventCallback&amp;lt;IEnumerable&amp;lt;PicklistSetDto&amp;gt;&amp;gt; SelectedValuesChanged { get; set; }

    protected List&amp;lt;PicklistSetDto&amp;gt; Options = new();

    private List&amp;lt;PicklistSetDto&amp;gt; _internalSelectedValues = new();

    private List&amp;lt;PicklistSetDto&amp;gt; InternalSelectedValues
    {
        get =&amp;gt; _internalSelectedValues;
        set
        {
            if (!_internalSelectedValues.SequenceEqual(value ?? new()))
            {
                _internalSelectedValues = value ?? new();
                SelectedValuesChanged.InvokeAsync(_internalSelectedValues);
            }
        }
    }

    protected override async Task OnInitializedAsync()
    {
        Options = await Task.FromResult(PicklistService.DataSource
            .Where(x =&amp;gt; x.Name == Name)
            .ToList());
    }

    public override async Task SetParametersAsync(ParameterView parameters)
    {
        await base.SetParametersAsync(parameters);

        InternalSelectedValues = Options
            .Where(x =&amp;gt; SelectedValues.Any(s =&amp;gt; s.Value == x.Value))
            .ToList();
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=2217441687434629520&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt; Example Usage in Parent Component&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;PicklistMultiSelect Label=&quot;Select Colors&quot;
                     Name=&quot;Picklist.Color&quot;
                     SelectedValues=&quot;@colorData&quot;
                     SelectedValuesChanged=&quot;OnColorChanged&quot; /&amp;gt;

private List&amp;lt;PicklistSetDto&amp;gt; colorData = new();
private void OnColorChanged(IEnumerable&amp;lt;PicklistSetDto&amp;gt; values)
{
    colorData = values.ToList();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To efficiently handle large datasets in Syncfusion’s SfMultiSelect in Blazor, you should avoid loading the entire dataset into memory and instead use server-side filtering and paging. Here's how to implement it:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;SfMultiSelect TValue=&quot;List&amp;lt;PicklistSetDto&amp;gt;&quot;
               TItem=&quot;PicklistSetDto&quot;
               @ref=&quot;multiObj&quot;
               Placeholder=&quot;@Label&quot;
               @bind-Value=&quot;InternalSelectedValues&quot;
               AllowFiltering=&quot;true&quot;
               EnableVirtualization=&quot;true&quot;
               PopupHeight=&quot;300px&quot;
               Filtering=&quot;OnFilter&quot;&amp;gt;
    &amp;lt;MultiSelectFieldSettings Text=&quot;Text&quot; Value=&quot;Value&quot; /&amp;gt;
&amp;lt;/SfMultiSelect&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;⚠ EnableVirtualization=&quot;true&quot; improves rendering performance but requires paging logic in OnFilter.&lt;/p&gt;
&lt;p&gt;✅ 2. Implement OnFilter with Server-Side Querying&lt;br&gt;
Replace your in-memory filter with actual server-side filtering:&lt;/p&gt;
&lt;p&gt;✅ 1. Enable Virtualization&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;private async Task OnFilter(FilteringEventArgs args)
{
    args.PreventDefaultAction = true;

    // Server-side call (adjust as needed)
    var filtered = await PicklistService.GetFilteredAsync(Name, args.Text);

    await multiObj.FilterAsync(filtered, new Query());
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;✅ 3. Modify Your Service to Support Filtering and Paging&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public async Task&amp;lt;List&amp;lt;PicklistSetDto&amp;gt;&amp;gt; GetFilteredAsync(Picklist name, string? filter)
{
    using var context = _dbContextFactory.CreateDbContext();

    var query = context.PicklistSets
        .Where(p =&amp;gt; p.Name == name);

    if (!string.IsNullOrWhiteSpace(filter))
        query = query.Where(p =&amp;gt; p.Text.Contains(filter));

    return await query
        .OrderBy(p =&amp;gt; p.Text)
        .Take(100) // Limit for performance
        .Select(p =&amp;gt; new PicklistSetDto
        {
            Value = p.Value,
            Text = p.Text,
            Name = p.Name
        })
        .ToListAsync();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;✅ 4. Optional – Add Debounce to Reduce API Calls&lt;/p&gt;
&lt;p&gt;This delays filtering execution until the user stops typing, avoiding too many API hits.&lt;/p&gt;
&lt;p&gt;DebounceDelay=&quot;300&quot;&lt;/p&gt;
&lt;p&gt; Why Use Syncfusion in Blazor?&lt;br&gt;
Syncfusion’s Blazor UI components offer a wide range of benefits for modern web apps. Here’s why it’s a great choice for developers:&lt;/p&gt;
&lt;p&gt;✅ 1. Rich Component Library&lt;br&gt;
Syncfusion provides 80+ production-ready components, including:&lt;/p&gt;
&lt;p&gt;SfGrid, SfMultiSelect, SfDatePicker, SfDialog, SfChart, and more&lt;/p&gt;
&lt;p&gt;Covers everything from data entry to dashboards&lt;/p&gt;
&lt;p&gt;⚡ 2. Performance Optimized&lt;br&gt;
Built-in virtualization and lazy loading&lt;/p&gt;
&lt;p&gt;Handles large datasets smoothly (e.g., thousands of records in a Grid)&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Consistent UI/UX&lt;br&gt;
Beautiful, modern design out of the box&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Theme support: Fluent, Bootstrap5, Material, Tailwind, or your custom styles&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Developer Productivity&lt;br&gt;
Intuitive APIs that follow Blazor standards (@bind-Value, DataSource, events)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Extensive documentation and real-world samples&lt;/p&gt;
&lt;p&gt;Native Blazor — not just JS interop wrappers&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Enterprise-Ready Features&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Built-in support for localization, accessibility (WCAG 2.0), and RTL&lt;/p&gt;
&lt;p&gt;Works seamlessly with validation frameworks like FluentValidation&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Excellent Integration with Modern Blazor Patterns&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Compatible with @inject, CascadingParameter, and EventCallback&lt;/p&gt;
&lt;p&gt;MVVM-friendly (e.g., CommunityToolkit.MVVM)&lt;/p&gt;
&lt;p&gt;Supports reactive forms and dynamic configuration&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Strong Commercial Support&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Regular updates and new feature rollouts&lt;/p&gt;
&lt;p&gt;Dedicated support via forums and ticket system&lt;/p&gt;
&lt;p&gt;Source code access included in paid plans&lt;/p&gt;
</description>
<category>Web Dev</category>
<guid isPermaLink="true">https://coderlegion.com/4311/creating-a-syncfusion-multiselect-component-with-two-way-binding-in-blazor</guid>
<pubDate>Tue, 29 Jul 2025 08:55:27 +0000</pubDate>
</item>
</channel>
</rss>