View Source Backpex.Metrics.Value (Backpex v0.8.2)
Value metrics display only a single value. This value is generated from the current index query by applying the given aggregate function. The selected value is processed by the specified formatting function and output in the frontend.
Options
:module
- Defines the module to handle the metric.:label
- Label text to define a headline for the metric.:select
- Dynamic query expression defining the column to select. This is usually an aggregate function.:format
- Optional format function to post-process the selected value from the database to display in frontend.:class
- Optional extra css classes to be passed to the metric box.
Example
In the following example we have a live resource products
with a value quantity
. We use the select
option here
to pass an aggregate function that adds up the quantity
value of all products currently active in the index view.
@impl Backpex.LiveResource
def metrics do
[
total_quantity: %{
module: Backpex.Metrics.Value,
label: "In Stock",
class: "w-1/3",
select: dynamic([i], sum(i.quantity)),
format: fn value ->
Integer.to_string(value) <> " Products"
end
}
]
end
Summary
Functions
Formats the selected data to display in frontend.
Performs database select to query the value of the metric
Attributes
metric
(:any
) (required) - the metric to be rendered.