SfMultiSelect that has empty list after clearing selected values

Hi,

I have problem with SfMultiSelect that has empty list (even if the data source not empty) after clearing selected values if I press clear button "x",consedering that i have a dynamic  SfMultiSelect  that each one represent a filtre to the next and this problem happening only if the SfMultiSelect list data has changed (has been filtred) ,so what i want to resolve this problm is to create funct to clear selected values whene I press clear button, here is the code :

<SfMultiSelect TValue="ExpandoObject[]" TItem="ExpandoObject" ShowDropDownIcon="true" Placeholder="@Localizer.GetText($"{Placeholder}")" PopupHeight="400px" DataSource="@FilterItems" CssClass="e-multi-column"

    AllowFiltering="true" Value="@selectedItems.ToArray()" Mode="VisualMode.CheckBox" ShowSelectAll="true" EnableVirtualization="true">

    <MultiSelectEvents TValue="ExpandoObject[]" TItem="ExpandoObject" ValueChange="@(args => OnValueChange(args))"></MultiSelectEvents>

    <MultiSelectTemplates TItem="ExpandoObject" Context="FContext">

        <HeaderTemplate>

            <table>

                <thead>

                    <tr>

                        @foreach (var column in SelectedColumns)

                        {

                            <th>@column.Value</th>

                        }

                    </tr>

                </thead>

            </table>

        </HeaderTemplate>

        <ItemTemplate>

            <table>

                <tbody>

                    <tr>

                        @foreach (var column in SelectedColumns)

                        {

                                var expandoDict = FContext as IDictionary<string, object>;

                                if (expandoDict != null && expandoDict.ContainsKey(column.Key.ToLower()))

                                {

                                    <td>@expandoDict[column.Key.ToLower()]</td>

                                }

                                else

                                {

                                    <td>@Localizer.GetText("Not Found")</td>

                                }

                        }

                    </tr>

                </tbody>

            </table>

        </ItemTemplate>

    </MultiSelectTemplates>

    <MultiSelectFieldSettings Text="@TextField" Value="@ValueField" />

</SfMultiSelect>


Best regards.



1 Reply

YS Yohapuja Selvakumaran Syncfusion Team February 21, 2025 05:18 AM UTC

Hi Mhmd

Thank you for reaching out to us.

We have carefully reviewed your code and created a sample based on your implementation. In our testing, we observed that after clearing the selected values using the clear button ("x"), the data source remains unchanged, and the dropdown list continues to display the available items as expected. Please find the attached sample for your reference.

We noticed that you are using the Value property to bind the selected values. Instead, we recommend using @bind-Value. This ensures two-way data binding, allowing the selected values to update properly when the clear button is pressed. The modified syntax would be:

<SfMultiSelect TValue="ExpandoObject[]" TItem="ExpandoObject"
    ShowDropDownIcon="true" Placeholder="@Localizer.GetText($"{Placeholder}")"
    PopupHeight="400px" DataSource="@FilterItems" CssClass="e-multi-column"
    AllowFiltering="true" @bind-Value="selectedItems"
    Mode="VisualMode.CheckBox" ShowSelectAll="true" EnableVirtualization="true">
</SfMultiSelect>

By using @bind-Value, the selectedItems list will automatically update when an item is selected or removed, preventing any inconsistencies in the displayed list.

If you are still facing the issue where the dropdown appears empty after clearing the selection, it could be due to the way the FilterItems list is updated dynamically. In such cases, we suggest verifying whether:

  1. The FilterItems list is being properly refreshed when the selection changes.
  2. There are no external factors modifying the FilterItems list unexpectedly.

To help us analyze the issue further, could you please share a runnable sample demonstrating the problem? This will allow us to test the behavior in a controlled environment and provide you with an accurate solution.


Regards,

Yohapuja S



Attachment: Multiselect_expando_30f25864.zip

Loader.
Up arrow icon