Skip to content

ImageColumn

Small round pictures, e.g. the people responsible for a record. Without a picture the column shows the initials on a colour that belongs to the name, the same in every list.

use Anvil\Collection\Columns\ImageColumn;
// one user: the initials and, with withLabel(), the name next to them
ImageColumn::make('owner_id')->label('Owner')->user()->withLabel(),
// several users: overlapping, at most three, then "+2"
ImageColumn::make('assignees')->label('Responsible')
->state(fn (array $task): array => $this->assigneeIds($task))
->user()
->limit(3),
// records of another model with a picture of the application
ImageColumn::make('team_id')->relationship(TeamModel::class)
->src(fn (mixed $id, array $record): ?string => '/teams/logo/' . $id),

The value is one item or a list of items – ids of users, ids of records of another model, or names. A list usually comes from state(). Empty items, and records the user may not see, are left out.

Option Meaning
user() the items are ids of users of the tenant; the name is the username, like TextColumn::user()
relationship(model, titleAttribute) the items are ids of records of another model; the name is their title, read like a relationship
src(fn ($item, $record) => …) the picture of an item: a path of the application, or null for the initials
limit(3) how many pictures are shown; the others are counted, e.g. +2
withLabel() shows the name next to the picture when there is only one

The column also takes the options of every column.

  • Initials: the first letters of the first two words, or the first two letters of a single word: Lena Schmidt → LS, leitung.it → LI.
  • Names: shown as tooltip and read by screen readers; the pictures themselves are decoration.
  • Exports contain the names, separated by commas.
  • Pictures only come from paths of the application (/…). Other sources – external URLs, data: or javascript: – show the initials instead, so the Content Security Policy (img-src 'self') holds and no browser loads images from elsewhere.
  • Names are escaped. With user() or relationship() the names come from the tenant; users only see records of a resource they may view.