Widgets above the list
listWidgets() of the resource shows widgets above the list, e.g. key
figures. They work like dashboard widgets:
users only see widgets they may view, values are computed when the list is
shown. Query through $this->query(), so the tenant and scopeQuery()
apply:
public function listWidgets(): array{ return [ StatWidget::make('Open')->icon('inbox')->span(4) ->value(fn () => $this->query()->where('status', 'open')->countAllResults()), StatWidget::make('Overdue')->icon('alarm')->color('danger')->span(4) ->value(fn () => $this->query()->where('due_on <', date('Y-m-d'))->where('status', 'open')->countAllResults()), ];}Following the list
Section titled “Following the list”These widgets show the totals of all records the user may see. A
StatWidget with fromList() follows the search and filters instead: it
gets the query of the list and is updated with every change of the list.
StatWidget::make('Open in this list')->icon('inbox') ->fromList(fn (Model $records): int => $records->where('status', 'open')->countAllResults()),Own widgets follow the list by implementing Anvil\Widget\ListAware.
Related lists on the detail page show no widgets. More on widgets:
Widgets.