Skip to content

Repository files navigation

Index Views

Save and switch between named views on your element indexes.

Your editors spend all day in the entries index. They set columns, sort by post date, filter to their section and switch to cards view. Then they open an entry, come back, and find it all reset. Craft keeps some of this in the browser, but only one configuration per source, only in localStorage, and filters are lost on navigation. Custom Sources help, but they need admin access and live in project config. They are a developer tool, not an editorial workflow.

Index Views lets any control panel user save the current index state as a named view and restore it with one click. Columns, sort, filters, view mode and source are all saved in the database.

Supported element types

  • Entries
  • Assets
  • Categories
  • Users

Other plugins can add their own element types:

use craft\events\RegisterComponentTypesEvent;
use yii\base\Event;
use zeixcom\craftindexviews\services\ViewsService;

Event::on(ViewsService::class, ViewsService::EVENT_REGISTER_ELEMENT_TYPES, function(RegisterComponentTypesEvent $event) {
    $event->types[] = Product::class;
});

What gets saved

  • Selected source (for example "Blog" or "All Entries")
  • Table columns and their order
  • Sort attribute and direction
  • View mode (table or cards)
  • Active condition builder filters
  • Search text
  • Site context (for multisite installs)

Note: If you save a view with a search term, loading that view restores the search term. To search freely inside a view, save the view without a search term, or clear the search box before you save.

How it works

  • A Views dropdown appears in the element index toolbar.
  • Save current view... saves the current state.
  • Click a saved view to restore it. The button shows the name of the active view.
  • Reset view deactivates the current view and returns to the default index state.
  • Update current view saves the current state into the active view.
  • Click the pencil icon to rename a view in place.
  • Click the copy icon to duplicate a view. The copy is always personal.
  • Drag the grip handle to reorder your personal views.
  • Hide and unhide views without deleting them.
  • Click the x button twice to delete a view. The first click asks for confirmation.
  • Point at a view to see its source, mode, sort, column count and filter status.

Default views

Click the star on a view to make it your default for the source it was saved on. When you open that index again, the view loads automatically.

  • One default per source, per element type, per user. A "Blog" default and a "News" default can both exist.
  • Defaults also work on shared views. Each user sets their own star. If you star a shared view, it does not change for other users.
  • Reset view clears the active view but keeps the star. The default applies again on your next visit.
  • If you delete a view, Craft clears all stars that point at it, for every user.

Dynamic conditions

Entries only. A view can include a dynamic condition that filters entries by the current user. Turn on Dynamic condition when you save or edit a view, then choose a Match condition:

  • Author is current user filters entries by author. No further configuration is needed.
  • {Field} is current user filters entries where a Users field (for example reviewer) points to the current user.
  • {Field} is related to current user via... filters entries through a chained relation. Use Resolve via to select the Users field on the intermediary entry.

The server resolves the condition on each page load. Every user sees only their own matching entries. This also applies to shared views.

Example: A "Scope Projects" section has a projectLead entries field that points to employee entries. Each employee entry has a linkedUser Users field. A shared view "My Projects" with the condition "projectLead is related to current user via linkedUser" shows each user only the projects that they lead.

Sharing

Views are personal by default. Users with the Share views with other users permission see a toggle when they save a view. This toggle makes the view visible to all control panel users.

Shared views appear in a separate "Shared Views" section. Only the user who created a shared view can rename or update it. Admins can delete any shared view.

Permissions

Permission What it controls
Share views with other users The toggle that makes a view visible to the whole team
Admin (Craft built-in) Deletes any shared view, including views created by other users

Why not Custom Sources?

Custom Sources Index Views
Who can create Admins only Any control panel user
Stored in Project config (deploys globally) Database (per user)
More than one preset per source No Yes
Saves ad-hoc filters No Yes
Survives cache clear Yes Yes
Shareable with team Always global Optional, per view
Per-user dynamic filtering No Yes

Requirements

  • Craft CMS 5.9 or later
  • PHP 8.2 or later

Installation

composer require zeixcom/craft-index-views
./craft plugin/install index-views

No configuration is necessary. The Views dropdown appears automatically on all supported element index pages.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages