Titles and references

Control how a record is named and displayed when other records refer to it

Introduction

Every record has a title which is used in various places in StellarAdmin. For example, when you edit a record, the title of the page will display the title of the record.

The title of the guide resource used as the edit page title

Likewise, when a resource is referred to from another resource (i.e. when there is a foreign-key relationship), the title of the resource will be used.

The title of the guide resource used as a reference in a grid

Choosing the title

The resource title is determined in the following order.

  1. The string property named by the class's [DisplayColumn] attribute.
  2. A string property called Name or Title.
  3. The key.

For example, a Destination with a Name property uses the destination's name as its title. To use a different property, call UseTitle():

admin.AddEfCoreResource<Guide>(resource =>
{
    resource.UseTitle(guide => guide.FirstName + " " + guide.LastName);
});

For an EF Core resource, the title must use only the entity's own properties, and EF Core must be able to translate it to SQL. A title that reads a related record isn't loaded for a column.

Displaying a description and media

Reference() configures how a record is displayed when someone selects it in a lookup or a select. You can add a description and an avatar.

admin.AddEfCoreResource<Guide>(resource =>
{
    resource.UseTitle(guide => guide.FirstName + " " + guide.LastName);
    resource.Reference(reference => reference
        .UseDescription(guide => guide.Email)
        .UseAvatar(guide => guide.PhotoUrl));
});
The title, email, and photo of a guide displayed in a reference

Searching, sorting and filtering references

For an EF Core resource, Reference() also configures how lookups search for records, the order records are returned in, as well as additional filter criteria.

resource.Reference(reference => reference
    .SearchOn(guide => guide.FirstName, guide => guide.LastName, guide => guide.Email)
    .OrderBy(guide => guide.LastName)
    .Where(guide => guide.IsActive));

In the code example above, when searching for a guide in a lookup, the user can search on the first name, last name, or email address. The guides displayed in the lookup are ordered by their last name, and only active guides are displayed.

Searching a guide based in their last name

Selecting a related record doesn't require access to its resource. Someone who can edit bookings can select a traveller for a booking, even if they can't manage travellers.

See selecting a related record for the fields that use references.

On this page