We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to stack selected items vertically in a Multiselct Dropdown?

Hi, I would like to know if there is a way to stack selected Items vertically rather than the horizontal stack and showing "+n More" for comma delimiter mode. I am after something like how the ListBox show the selected items for the Multiselect Dropdown as well. Basically I would like to see all the selected items stacked vertically without having to click the control possibly with a scroll bar on its side as well. Is this possible?

Thanks,

Harry


10 Replies 1 reply marked as answer

PM Ponmani Murugaiyan Syncfusion Team January 18, 2022 11:00 AM UTC

Hi Harryi, 

We checked your reported query. You can achieve your requirement using the Box mode in Multiselect component. 


<SfMultiSelect TValue="string[]" TItem="EmployeeData" ClosePopupOnSelect="false" HideSelectedItem="false" @bind-Value="@MultiVal" Mode="VisualMode.Box" Placeholder="Select a customer" DataSource="@Data">  
        <MultiSelectEvents TValue="string[]" TItem="EmployeeData" OnValueSelect="onSelect"></MultiSelectEvents>  
        <MultiSelectFieldSettings Value="FirstName"></MultiSelectFieldSettings>  
</SfMultiSelect> 
 

 
 

Kindly check with the above suggestion. Please get back us if you need further assistance. 

Regards, 
Ponmani M 



HA Harryi January 19, 2022 01:50 AM UTC

Hi Ponmani,


Thank you very much for getting back to me. However, I am more after listing each selected item comma delimited (without the colored grey box) and one item per row. Is this possible?

Thanks.



PM Ponmani Murugaiyan Syncfusion Team January 19, 2022 04:45 PM UTC

Hi Harryi, 

We have customized the UI as per your requirement by overriding the below styles. Kindly check with the below attached sample. 

<SfMultiSelect TValue="string[]" Width="300px" TItem="GameFields" Mode="@VisualMode.Box" Placeholder="Favorite Sports" DataSource="@Games"> 
    <MultiSelectFieldSettings Text="Text" Value="ID"></MultiSelectFieldSettings> 
</SfMultiSelect> 
@code{ 
    public class GameFields 
    { 
        public string ID { get; set; } 
        public string Text { get; set; } 
    } 
    private List<GameFields> Games = new List<GameFields>() 
{ 
        new GameFields(){ ID= "Game1", Text= "American Football" }, 
        new GameFields(){ ID= "Game2", Text= "Badminton" }, 
        new GameFields(){ ID= "Game3", Text= "Basketball" }, 
        new GameFields(){ ID= "Game4", Text= "Cricket" }, 
        new GameFields(){ ID= "Game5", Text= "Football" }, 
        new GameFields(){ ID= "Game6", Text= "Golf" }, 
        new GameFields(){ ID= "Game7", Text= "Hockey" }, 
        new GameFields(){ ID= "Game8", Text= "Rugby"}, 
        new GameFields(){ ID= "Game9", Text= "Snooker" }, 
        new GameFields(){ ID= "Game10", Text= "Tennis"} 
    }; 
} 
 
<style> 
    .e-multi-select-wrapper .e-chips-collection { 
        display: grid; 
    } 
    .e-multi-select-wrapper .e-chips { 
        background-color: white; 
    } 
    .e-multi-select-wrapper .e-chips > .e-chipcontent { 
        -webkit-text-fill-color: black; 
    } 
    .e-multi-select-wrapper .e-chips .e-chips-close::before { 
        -webkit-text-fill-color: #170606; 
    } 
    .e-multi-select-wrapper .e-chips:hover { 
        background-color: white; 
    } 
    .e-multi-select-wrapper .e-chips.e-chip-selected:hover { 
        background-color: white; 
    } 
    .e-multi-select-wrapper .e-chips.e-chip-selected { 
        background-color: white; 
    } 
</style> 

 


Regards, 
Ponmani M 



HA Harryi January 20, 2022 04:25 AM UTC

Hi Ponmani,


Thank you so much for your reply. Although this partially fixes my issue, I need the Multiselect Dropdown Mode to be "VisualMode.CheckBox". With your example I can stack the selections but cannot select multiple items at once without contracting the drop down menu. I need the Multiselect box to be as below so I can click "Select All" or select multiple items without closing the dropdown menu. Is it possible?


Thank you very much.



PM Ponmani Murugaiyan Syncfusion Team January 21, 2022 06:37 AM UTC

Hi Harryi,  

In Multiselect CheckBox mode, the selected items shows the +n more, so the reported scenario cannot be customized in the CheckBox mode. However we can customize the checkbox UI in the popup using ItemTemplate in the Box mode as like below code.  

We have prepared work-around for the requirement by create a Multiselect Box mod and customize popup UI with HearTemplate as SelectAll checkBox and ItemTemplate as list items with checkbox.  

<SfMultiSelect @ref="MultiObj" TValue="string[]" TItem="EmployeeData" ClosePopupOnSelect="false" HideSelectedItem="false" @bind-Value="@MultiVal" Mode="Syncfusion.Blazor.DropDowns.VisualMode.Box" Placeholder="Select a customer" DataSource="@Data"> 
                <MultiSelectTemplates TItem="EmployeeData"> 
                    <HeaderTemplate> 
                        @{  
                        <span> 
                            <SfCheckBox TChecked="bool" @bind-Checked="isChecked" @onclick="onClick" >SelectAll</SfCheckBox> 
                        </span> 
                         } 
                    </HeaderTemplate> 
                    <ItemTemplate> 
                        @{ 
                            var contextValue = (context as EmployeeData).FirstName; 
                            bool isChecked = MultiVal != null ? MultiVal.Contains(contextValue) : false; 
 
                            <span> 
                                <SfCheckBox TChecked="bool" @bind-checked="@isChecked"></SfCheckBox> 
                                @contextValue 
                            </span> 
                        } 
                    </ItemTemplate> 
                </MultiSelectTemplates> 
                <MultiSelectEvents TValue="string[]" TItem="EmployeeData" OnValueSelect="onSelect"></MultiSelectEvents> 
                <MultiSelectFieldSettings Value="FirstName"></MultiSelectFieldSettings> 
            </SfMultiSelect> 

When ever the header checkbox is clicked we can update the value property with all values and can empty the items while uncheck. 

    private bool isChecked = false; 
    private async Task onClick(Microsoft.AspNetCore.Components.Web.MouseEventArgs args) 
    { 
        if (isChecked == false) 
        { 
            isChecked = true; 
            MultiVal = new string[] { "Andrew Fuller", "Anne Dodsworth", "Janet Leverling", "Laura Callahan", "Margaret Peacock" }; 
        } 
        else 
        { 
            isChecked = false; 
            MultiVal = new string[] { }; 
        } 
    } 
} 

 


Regards, 
Ponmani M 


Marked as answer

HA Harryi January 27, 2022 01:40 AM UTC

Hi Ponmani,


Thank you for getting back to me. Very clever to change the styles and make it stack the selected items vertically. Although, by doing this I lose the Filter functionality. This is a must when using the multiselect dropdown because there will be many items to choose from.

Also when the selected items get stacked, the text field grows downward. Is there a way to make it fixed and add a scrollbar instead?


Thanks,

Harry



PM Ponmani Murugaiyan Syncfusion Team January 27, 2022 12:20 PM UTC

Hi Harryi 

Query1: Although, by doing this I lose the Filter functionality. This is a must when using the multiselect dropdown because there will be many items to choose from.  
 
You can use the filter option by enabling the AllowFiltering property as true to meet your requirement. 

            <SfMultiSelect @ref="MultiObj" TValue="string[]" TItem="EmployeeData" ClosePopupOnSelect="false" AllowFiltering="true" HideSelectedItem="false" @bind-Value="@MultiVal" Mode="Syncfusion.Blazor.DropDowns.VisualMode.Box" Placeholder="Select a customer" DataSource="@Data"> 


Query2: Also when the selected items get stacked, the text field grows downward. Is there a way to make it fixed and add a scrollbar instead? 
 
Yes, by overriding the below styles, you can make the fixed height and set scroll bar to the input as expected. 
 
  .e-multi-select-wrapper { 
        height: 100px; 
        overflow: overlay; 
    } 
 

Regards, 
Ponmani M 



HA Harryi February 1, 2022 07:48 AM UTC

Hi Ponmani,


Thank you so much for this. However, there is a small issue when this is tested with Firefox browser. The selected text outgrows the border as below..



HA Harryi replied to Harryi February 1, 2022 10:22 PM UTC

Hi Ponmani,


I was able to fix the above mentioned issue by changing it to "Overflow: scroll". Thank you very much for the effort that you've put in to providing me this solution.


Harry.



PM Ponmani Murugaiyan Syncfusion Team February 2, 2022 07:44 AM UTC

Hi Harryi,    

Welcome, we are glad to hear that the issue has been resolved. Please get back us if you need further assistance. 

Regards, 
Ponmani M 


Loader.
Live Chat Icon For mobile
Up arrow icon