Skip to content

Saved views

Lists remember how a user left them, users can save named views, and the application can define views for everybody (presets).

Toggleable columns appear in the column menu of the toolbar. The hidden columns and the chosen view (table or cards) are remembered per user and list, and the list opens with them next time. They are personal preferences: stored without an audit entry, not shared with other users.

Users can save the current state of a list as a named view: search, filters, sort, page size, table or cards, hidden columns and grouping. A view can be applied, deleted or marked as default; the list then starts with it instead of the remembered layout.

  • Views are personal: stored per user, tenant and list in anvil_collection_views (run the migrations) and referenced by UUID. Views of other users are not found.
  • A saved view is applied like user input: filters or columns that no longer exist fall back to the defaults. Number filters are saved normalised and shown in the current locale.
  • At most 20 views per user and list. Views are preferences, not business data, and are not written to the audit log.
  • Related lists on the detail page offer the column menu, but neither remember the layout nor offer saved views.

Presets are views defined in code, the same for all users. They are listed first in the views menu, cannot be changed by users, and can be marked as personal default like saved views. default() makes one the start of every user without a default of their own; a user can switch it off with the star.

use Anvil\Collection\Views\Preset;
->presets([
Preset::make('open', 'Purchase.presets.open')->filters(['approval_state' => 'draft,submitted,in_review'])->default(),
Preset::make('my-tasks', 'Purchase.presets.myTasks')->filters(['my_tasks' => '1']),
Preset::make('ordered', 'Ordered')->filters(['approval_state' => 'ordered'])->sort('amount', 'desc'),
])
Method Meaning
Preset::make('key', 'Label') key: lower case letters, digits and -; the label may be a language key
filters([...]) filter name => value, see values per filter
search('…'), sort('column', 'desc'), view('cards') search, sorting and view
hidden([...]) hidden columns; without it the user’s column choice stays
group('column') the grouping, null for none; without it the default of the collection
default() the start of all users without a default of their own; one per list

A widget can open a list with a preset, e.g. a figure “Open requests” that opens the preset open.

  1. the user’s default view or preset,
  2. the default preset of the list,
  3. the remembered layout and the defaults of the collection (defaultSort(), perPage(), views()).

Presets are checked like user input, so a filter that no longer exists is ignored.