SfMultiSelect - GroupBy Hide Item

Is it possibly to hide an item? For instance if my item has no sub items rather than repeating the text just hide it.

x Pipeline

     x Pipeline > hide this item
x PQQ

    x Confirm
    x Approve
x Secured
 x Secured > hide this item

Thought was getting close with this:

<MultiSelectTemplates TItem="QueryLine">
<ItemTemplate>
@{
var ctx = context;
if (ctx.CacheName != ctx.DisplayPath)
{
<span>@context.DisplayPath</span>
}
else
{
<div style="display: none"></div>
}
}


</ItemTemplate>
</MultiSelectTemplates>

7 Replies

YA YuvanShankar Arunagiri Syncfusion Team September 1, 2025 11:38 AM UTC

Hi Lee,


We have validated your requirement related to the ListBox component and the scenario you reported. Based on your shared code snippet and explanation, we understand that you're attempting to hide duplicate items using the ItemTemplate tag.

For clarification: in our source implementation, the ItemTemplate element is rendered inside the <li> element of the MultiSelect popup. Even if you hide the item content using your approach, the corresponding <li> element still exists, resulting in empty list items being displayed.

To resolve this issue, we recommend using one of the following workaround solutions:


  • Remove duplicate items before rendering the MultiSelect component.

protected override async Task OnInitializedAsync()

{

    LocalData = LocalData.Where(v => v.Vegetable != v.Category).ToList();

}

  • Use JavaScript interop to hide specific list items dynamically.

[Home.razor]:

<SfMultiSelect CssClass="e-custom-popup" TValue="string[]" TItem="Vegetables" Placeholder="Select a vegetable" DataSource="@LocalData">

          <MultiSelectEvents TValue="string[]" TItem="Vegetables" Opened="Opened"></MultiSelectEvents>

………..

<ItemTemplate>

    @{

        if (context.Category == context.Vegetable)

        {

            <span class="e-hidden-list">@context.Vegetable</span>

        }

…..

  private async void Opened(PopupEventArgs args)

  {

      await JS.InvokeVoidAsync("HideDuplicateItems");

  }


[App.razor]:

<script>

    window.HideDuplicateItems = () => {

        setTimeout(function() {

            var popupElement = document.querySelector('.e-custom-popup.e-popup-open');

            if (popupElement) {

                var hiddenElement = popupElement.querySelectorAll('.e-hidden-list');

                for(var i = 0; i < hiddenElement.length; i++) {

                    hiddenElement[i].parentElement.style.display = 'none';

                }

            }

        }, 100);

    }

</script>


  • Apply custom CSS styles to hide unwanted items.

<style>

    .e-list-item:has(.e-hidden-list) {

        display: none;

    }

</style>


Note: Above custom CSS style applicable only for Chrome from version 105 and above, Edge from version 105 and above, Safari from version 15.4 and above, Firefox does not support: has() yet; it's still under development.


Please get back to us if you have any concerns or need further clarification.


Regards,

YuvanShankar A


Attachment: MultiSelecthideitems_8a708305.zip


LS Lee Stevens September 1, 2025 06:42 PM UTC

Thank you kindly for the excellent reply. 

Anyway sorry didn't explain it that well. But I'm sure you'll have the answer.

If the group has no sub items, I want to hide the sub-item (repetitive text) and just display the group header.
So using your example page, I would only want to see the 'Onion' category and not the 'Onion' vegetable.

My business object is quite complex hence using yours. Mine is for a main status and a sub status and sometimes the main status doesn't have a sub status if that makes more sense.

@page "/"

@using Syncfusion.Blazor.DropDowns
@inject IJSRuntime JS

<SfMultiSelect EnableGroupCheckBox="true"
CssClass="status-multiselect"
Mode="VisualMode.CheckBox"
TValue="string[]"
TItem="Vegetables"
Placeholder="Select a vegetable"
DataSource="@LocalData">
<MultiSelectEvents TValue="string[]" TItem="Vegetables" Opened="Opened"></MultiSelectEvents>
<MultiSelectFieldSettings GroupBy="Category" Value="ID" Text="Vegetable"></MultiSelectFieldSettings>
<MultiSelectTemplates TItem="Vegetables">
<ItemTemplate>
@{
if (context.Category == context.Vegetable)
{
<span class="e-hidden-list">@context.Vegetable</span>
}
else
{
<span>@context.Vegetable</span>
}
}
</ItemTemplate>
</MultiSelectTemplates>

</SfMultiSelect>

@code {

public List<Vegetables> LocalData { get; set; } = new Vegetables().VegetablesList();

private async void Opened(PopupEventArgs args)
{
await JS.InvokeVoidAsync("HideDuplicateItems");
}

public class Vegetables
{
public string Vegetable { get; set; }
public string Category { get; set; }
public string ID { get; set; }

public List<Vegetables> VegetablesList()
{
var Veg = new List<Vegetables>();
Veg.Add(new Vegetables { Vegetable = "Cabbage", Category = "Leafy and Salad", ID = "item1" });
Veg.Add(new Vegetables { Vegetable = "Leafy and Salad", Category = "Leafy and Salad", ID = "item133" });
Veg.Add(new Vegetables { Vegetable = "Chickpea", Category = "Beans", ID = "item2" });
Veg.Add(new Vegetables { Vegetable = "Garlic", Category = "Bulb and Stem", ID = "item3" });
Veg.Add(new Vegetables { Vegetable = "Green bean", Category = "Beans", ID = "item4" });
Veg.Add(new Vegetables { Vegetable = "Nopal", Category = "Bulb and Stem", ID = "item6" });
Veg.Add(new Vegetables { Vegetable = "Pumpkins", Category = "Leafy and Salad", ID = "item8" });
Veg.Add(new Vegetables { Vegetable = "Onion", Category = "Onion", ID = "item9" });
return Veg;
}
}

}

<style>

.status-multiselect .e-list-group-item {
font-weight: bold;
padding-left: 1rem;
}

/* Style child items (substatuses) */
.status-multiselect .e-list-group-item ~ .e-list-item {
padding-left: 2rem;
}
</style>



YA YuvanShankar Arunagiri Syncfusion Team September 2, 2025 07:28 AM UTC

Hi Lee,


We understand your requirement regarding the MultiSelect component and the scenario you reported.

By default, the MultiSelect component uses the Category field in the data source to group items. Even if the Category and Vegetable fields have the same value, the component will still render them separately as a group header and a list item. This is the expected behavior of the MultiSelect component.

To achieve your requirement where categories with only one item (and where the Category and Vegetable values are the same) should not display the list item you can follow this approach:

  1. Add a Boolean property (e.g., CanHide) to your data model.
  2. Set CanHide = true for items where the category has only one item and the Category and Vegetable values are identical.
  3. Bind this property to the Disabled field in the MultiSelect component’s FieldSettings. This will mark the item as disabled.
  4. Use custom CSS to hide disabled items from the dropdown list.


SfMultiSelect EnableGroupCheckBox="true"

    …………

        <MultiSelectFieldSettings GroupBy="Category" Value="ID" Text="Vegetable" Disabled="CanHide"></MultiSelectFieldSettings>

        …………

</SfMultiSelect>

 

……..

    public class Vegetables

    {

        ……….

        public bool CanHide { get; set; }

 

        public List<Vegetables> VegetablesList()

        {

            …………

 

            // Count items per category

            var categoryCounts = vegList.GroupBy(v => v.Category).ToDictionary(g => g.Key, g => g.Count());

 

            // Set CanHide = true for items in categories with only one item

            foreach (var veg in vegList)

            {

                veg.CanHide = categoryCounts[veg.Category] <= 1;

            }

 

            return vegList;

        }

    }

}

 

<style>

 

    .status-multiselect .e-list-group-item ~ .e-list-item.e-disabled {

        display: none;

    }

</style>

 


Output Screenshot:


Kindly get back to us if you have any concerns or need further clarification.


Regards,

YuvanShankar A


Attachment: MultiSelect_b2e76961.zip


LS Lee Stevens September 4, 2025 11:34 AM UTC

Hi - Ok I like that idea and yes it work...almost.....

You have now disabled the Group Onion but I still need it clickable :)



MR Mallesh Ravi Chandran Syncfusion Team September 9, 2025 04:22 AM UTC

We understand the desire to have disabled items appear as selected. However, this is intentionally not supported for the following reasons:


Disabled items are meant to be non-interactive: By definition, a disabled item indicates that it is not available for selection or interaction. Displaying it as selected would contradict its disabled state and create confusion for users.

Consistency and clarity in user experience: Showing a checkbox as checked while the item is disabled can lead to ambiguity. Users may assume the item is active or editable, which is not the case.

Input field integrity: To maintain a clean and accurate representation of selected values, disabled items are excluded from both the checkbox state and the input field. This ensures that only valid, user-selectable items are reflected.


This behavior is designed to align with standard UI/UX principles and to prevent potential misinterpretation or unintended actions.


LS Lee Stevens replied to Mallesh Ravi Chandran September 9, 2025 06:28 AM UTC

It was not my desire to have a disabled item as selected at all! You suggested using the disabled property as a hack for hiding an item. However that does not work as we now cannot select the item.

See above!

  1. Add a Boolean property (e.g., CanHide) to your data model.
  2. Set CanHide = true for items where the category has only one item and the Category and Vegetable values are identical.
  3. Bind this property to the Disabled field in the MultiSelect component’s FieldSettings. This will mark the item as disabled.
  4. Use custom CSS to hide disabled items from the dropdown list.




YA YuvanShankar Arunagiri Syncfusion Team September 12, 2025 10:09 AM UTC

Hi Lee,


We apologize for the inconvenience. We have reviewed your requirement related to the MultiSelect component. When a list item is disabled using the enabled field property, it becomes non-interactive by design.

To achieve your requirement of hiding single group items while keeping the group header checkbox clickable, we recommend using a JavaScript interop workaround. This approach is clean and does not involve any hacks. It allows you to hide specific items and maintain the expected behavior of the group header checkbox.

Please refer to the code snippet and the attached sample for implementation details.


[Home.razor]:

<SfMultiSelect EnableGroupCheckBox="true" CssClass="status-multiselect" Mode="VisualMode.CheckBox" TValue="string[]" TItem="Vegetables" Placeholder="Select a vegetable" DataSource="@LocalData">

    <MultiSelectFieldSettings GroupBy="Category" Value="ID" Text="Vegetable"></MultiSelectFieldSettings>

    <MultiSelectEvents TItem="Vegetables" TValue="string[]" Opened="Opened"></MultiSelectEvents>

    <MultiSelectTemplates TItem="Vegetables">

        <ItemTemplate>

            @if (categoryCounts[context.Category] <= 1)

            {

                <span class="e-hide-item">@context.Vegetable</span>

            }

            else

            {

                <span>@context.Vegetable</span>

            }

        </ItemTemplate>

    </MultiSelectTemplates>

</SfMultiSelect>

 

    public dynamic categoryCounts;

 

    private async void Opened(PopupEventArgs args)

    {

        await JS.InvokeVoidAsync("hideItems", "status-multiselect");

    }

….

    protected override async Task OnAfterRenderAsync(bool firstRender)

    {

        if (firstRender)

        {

            categoryCounts = LocalData.GroupBy(v => v.Category).ToDictionary(g => g.Key, g => g.Count());

        }

    }

}


[App.razor]:

<script>

    window.hideItems = (className) => {

        setTimeout(function(){

            var popupElem = document.querySelector(`.${className}.e-popup-open`);

            if (popupElem) {

                var spanElem = popupElem.querySelector('.e-hide-item');

                if (spanElem) {

                    spanElem.parentElement.style.display = 'none';

                }

            }

        },70);

    }

</script>


Output screenshot:


Please let us know if you need any further assistance on this.


Regards,

YuvanShankar A


Attachment: multselecthideitems_cf1e9dae.zip

Loader.
Up arrow icon