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:

PropertyDisplay type
stringTextDisplay
string with [EmailAddress]EmailDisplay
string with [Phone]PhoneDisplay
string with [Url]LinkDisplay
string with [DataType(DataType.Html)]HtmlDisplay
NumbersNumberDisplay
DateOnly, DateTime, DateTimeOffset, TimeOnlyDateDisplay
boolBooleanDisplay
EnumEnumDisplay
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 valueBadgeDisplay

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";
            }));
    }));
});
The travellers grid with Subscribed or Not subscribed in the Marketing opt-in column

You can find more details on the various display types on the following pages:

Display typePage
TextDisplay, HtmlDisplayText
NumberDisplay, DateDisplayNumbers and dates
BooleanDisplay, EnumDisplayBooleans and enums
EmailDisplay, PhoneDisplay, LinkDisplayLinks and emails
BadgeDisplayBadges
ImageDisplayImages
IconDisplayIcons

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.

On this page