Overview
How StellarAdmin chooses how a value is displayed, and how to choose another display type
A display type determines how a value is displayed on a resource's view page, in a display field, and in grids. StellarAdmin chooses each value's display type from the property's type and attributes as follows:
| Property | Display type |
|---|---|
string | TextDisplay |
string with [EmailAddress] | EmailDisplay |
string with [Phone] | PhoneDisplay |
string with [Url] | LinkDisplay |
string with [DataType(DataType.Html)] | HtmlDisplay |
| Numbers | NumberDisplay |
DateOnly, DateTime, DateTimeOffset, TimeOnly | DateDisplay |
bool | BooleanDisplay |
| Enum | EnumDisplay |
List of strings or numbers, such as List<string> or int[] | BadgeDisplay |
| Dictionary with a string or enum key, and a string, number or enum value | BadgeDisplay |
Choosing another display type
To use another display type, call UseDisplay() on the column or the display field. To change the display type's settings, pass a callback function. The example below displays whether a traveller has opted in to marketing as text instead of an icon:
using StellarAdmin.Resources.Displays;
admin.AddEfCoreResource<Traveller>(resource =>
{
resource.Index(index => index.Columns(columns =>
{
columns.Add(traveller => traveller.FirstName);
columns.Add(traveller => traveller.LastName);
columns.Add(traveller => traveller.Email);
columns.Add(traveller => traveller.MarketingOptIn, column =>
column.UseDisplay<BooleanDisplay>(flag =>
{
flag.Appearance = BooleanDisplayAppearance.Text;
flag.TrueText = "Subscribed";
flag.FalseText = "Not subscribed";
}));
}));
});

You can find more details on the various display types on the following pages:
| Display type | Page |
|---|---|
TextDisplay, HtmlDisplay | Text |
NumberDisplay, DateDisplay | Numbers and dates |
BooleanDisplay, EnumDisplay | Booleans and enums |
EmailDisplay, PhoneDisplay, LinkDisplay | Links and emails |
BadgeDisplay | Badges |
ImageDisplay | Images |
IconDisplay | Icons |
For a display type StellarAdmin doesn't have, write a custom display.
Empty values
When a value is null or empty, StellarAdmin displays the column's or the field's EmptyText. If EmptyText isn't set, it uses the property's [DisplayFormat(NullDisplayText)]. Without either, the grid displays an empty cell, and a display field displays a dash.
ImageDisplay is the exception: it displays a placeholder for an empty value.