Grouped stats widget
Several key figures in one card, in titled groups side by side with a line between; on small screens the groups are below each other.
GroupedStatsWidget::make('Purchase requests')->icon('cart-check')->span(8) ->permission('purchase-requests.view') ->groups([ StatGroup::make('Open')->stats([ Stat::make('Draft')->icon('pencil')->numeric()->value(static fn (): int => $count('draft')) ->url($this->url('purchase-requests') . '?preset=open'), Stat::make('Submitted')->icon('send')->numeric()->value(static fn (): int => $count('submitted')), ]), StatGroup::make('Decided')->stats([ Stat::make('Approved')->color('success')->numeric()->value(static fn (): int => $count('approved')), Stat::make('Rejected')->color('danger')->numeric()->value(static fn (): int => $count('rejected')), ]), StatGroup::make('Volume')->stats([ Stat::make('approved')->money('EUR', 0)->value(static fn (): float => $sum('approved')), ]), ]);| Class and method | Description |
|---|---|
GroupedStatsWidget::make($label) |
title of the card; icon(), permission(), span() (default 12), key() as for the stat widget |
groups([StatGroup ...]) |
the groups in their order |
StatGroup::make($label) |
title of the group (may be empty); stats([Stat ...]), permission() |
Stat::make($label) |
one figure: value(Closure), icon(), color() (tone of the value), url(), permission() |
Stat::numeric($decimals), Stat::money($currency, $decimals) |
formats the value in the current locale; whole numbers are formatted anyway |
Labels may be language keys. Values are closures evaluated only when the widget is shown; compute several figures with one query and share the result between the closures. Figures and groups without permission are left out, a group without visible figures too.
A figure can open a list with a preset: the list page
takes ?preset=<key> (unknown keys are ignored).