Badges
Display a list, a dictionary, related records or a single value as badges
Introduction
BadgeDisplay displays a value as a badge, or each item of a collection as its own badge.


StellarAdmin uses BadgeDisplay by default for these properties:
- An array or list of strings or numbers, such as a trip's highlights. This covers
T[],List<T>,IList<T>,ICollection<T>,IEnumerable<T>,IReadOnlyList<T>andIReadOnlyCollection<T>. - A
Dictionary<TKey, TValue>orIDictionary<TKey, TValue>with a string or enum key, and a string, number or enum value. Each entry is displayed as a badge in the format<key>: <value>, for examplept: Passeio por Lisboa.
For other properties, you can explicitly call UseDisplay<BadgeDisplay>() to display related records or a single value as badges.
Limiting the number of badges
To limit the number from the collection that are displayed, set Limit. When there are more items than Limit, BadgeDisplay displays one more badge with the number of the other items, such as +2, and lists them when people hover over it. The example below displays at most 2 of a trip's departure airports, as outline badges:
using StellarAdmin.Resources.Displays;
using StellarAdmin.UI;
columns.Add(trip => trip.DepartureAirports, column =>
column.UseDisplay<BadgeDisplay>(badge =>
{
badge.Variant = BadgeVariant.Outline;
badge.Limit = 2;
}));

BadgeDisplay has the following members:
| Member | Description |
|---|---|
Limit | Specifies the maximum number of badges displayed. The default is null, which displays every item in the list. |
Variant | Sets the variant of the badges, for example BadgeVariant.Outline. The default is Secondary. |
Every badge has the same Variant. To vary a badge's variant depending on its value, use a custom display.
Displaying related records as badges
You can display a collection of related records, such as a trip's tags, using UseDisplay<BadgeDisplay>(). When the related type is a resource, each badge displays the record's title:
columns.Add(trip => trip.Tags, column => column.UseDisplay<BadgeDisplay>());

When the related type isn't a resource, call UseText() to specify the text displayed inside the badge:
columns.Add(guide => guide.Trips, column =>
{
column.UseDisplay<BadgeDisplay>(badge => badge.UseText<Trip>(trip => trip.Title));
});Displaying a single value as a badge
BadgeDisplay can also display a single value, such as an enum member or a status, as one badge. The example below displays the trip's difficulty as a badge:
columns.Add(trip => trip.Difficulty, column => column.UseDisplay<BadgeDisplay>());To set the text of the badge, call UseText() with the type of the value.