Better support for customizing the label of DropDown-component #436

Closed
opened 2026-01-29 17:37:16 +00:00 by claunia · 1 comment
Owner

Originally created by @tkallsen on GitHub (Jun 15, 2022).

Hi,

When using RadzenDropDown with Multiple == true the selected items are always rendered with a "," between them. Preferably the default would be with ", " as the separator (comma with space) with additional support for customizing the text entirely.

Something like this in RadzenDropDown (and corresponding in other children of DropDownBase):

@(string.Join(", ", selectedItems.Select(i => PropertyAccess.GetItemOrValueFromProperty(i, TextProperty))))

and when using Template:

for (int i = 0; i < selectedItems.Count; i++)
{
    @(i != 0 ? ", ": "")@Template(selectedItems[i])
}

Another option for complete customization (with backwards compatibility) would be to introduce a separate template for the label when using Multiple == true:

[Parameter]
public RenderFragment<IList<object>> MultipleItemsTemplate { get; set; }

and

@if (MultipleItemsTemplate != null)
{
   @(MultipleItemsTemplate(selectedItems))
}
else if (Template != null)
{
    for (int i = 0; i < selectedItems.Count; i++)
    {
        @(i != 0 ? ", ": "")@Template(selectedItems[i])
    }
}
else
{
    @(string.Join(", ", selectedItems.Select(i => PropertyAccess.GetItemOrValueFromProperty(i, TextProperty))))
}

static RenderFragment ExampleTemplate(IList<object> items) => builder =>
{
    builder.AddContent(0, new MarkupString(
        string.Join(" / ", items.Select(i => PropertyAccess.GetItemOrValueFromProperty(i, "Name")))));
};

If this is something that would be acceptable I can submit a PR.

Originally created by @tkallsen on GitHub (Jun 15, 2022). Hi, When using RadzenDropDown with `Multiple == true` the selected items are always rendered with a "," between them. Preferably the default would be with ", " as the separator (comma with space) with additional support for customizing the text entirely. Something like this in RadzenDropDown (and corresponding in other children of DropDownBase): ``` @(string.Join(", ", selectedItems.Select(i => PropertyAccess.GetItemOrValueFromProperty(i, TextProperty)))) ``` and when using Template: ``` for (int i = 0; i < selectedItems.Count; i++) { @(i != 0 ? ", ": "")@Template(selectedItems[i]) } ``` Another option for complete customization (with backwards compatibility) would be to introduce a separate template for the label when using `Multiple == true`: ``` [Parameter] public RenderFragment<IList<object>> MultipleItemsTemplate { get; set; } ``` and ``` @if (MultipleItemsTemplate != null) { @(MultipleItemsTemplate(selectedItems)) } else if (Template != null) { for (int i = 0; i < selectedItems.Count; i++) { @(i != 0 ? ", ": "")@Template(selectedItems[i]) } } else { @(string.Join(", ", selectedItems.Select(i => PropertyAccess.GetItemOrValueFromProperty(i, TextProperty)))) } ``` ``` static RenderFragment ExampleTemplate(IList<object> items) => builder => { builder.AddContent(0, new MarkupString( string.Join(" / ", items.Select(i => PropertyAccess.GetItemOrValueFromProperty(i, "Name"))))); }; ``` If this is something that would be acceptable I can submit a PR.
Author
Owner

@OndrejUzovic commented on GitHub (Jun 17, 2022):

I vote for this feature.
(E.g. if there is not enough space the delimiter ',' without extra space is useful but if there is a need to provide a more friendly/nicer visualization a custom template (where I could set own delimitation e.g. ', ') would be much better solution.)

@OndrejUzovic commented on GitHub (Jun 17, 2022): I vote for this feature. (E.g. if there is not enough space the delimiter ',' without extra space is useful but if there is a need to provide a more friendly/nicer visualization a custom template (where I could set own delimitation e.g. ', ') would be much better solution.)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#436