View Source Backpex.Filters.Select behaviour (Backpex v0.8.2)
Tbe select filter renders a select box for the implemented options/0
and prompt/0
callbacks. The prompt/0
callback defines the key for the nil
value added as first option.
See the following example for an implementation of an event status filter.
defmodule MyAppWeb.Filters.EventStatusSelect do
use Backpex.Filters.Select
@impl Backpex.Filter
def label, do: "Event status"
@impl Backpex.Filters.Select
def prompt, do: "Select an option..."
@impl Backpex.Filters.Select
def options, do: [
{"Open", :open},
{"Close", :close},
]
@impl Backpex.Filter
def query(query, attribute, value) do
where(query, [x], field(x, ^attribute) == ^value)
end
end
use Backpex.Filters.Select
When you
use Backpex.Filters.Select
, theBackpex.Filters.Select
module will set@behavior Backpex.Filters.Select
. In addition it will add arender
andrender_form
function in order to display the corresponding filter.
Summary
Functions
Attributes
value
(:any
) (required)options
(:list
) (required)
Attributes
form
(:any
) (required)field
(:atom
) (required)value
(:any
) (required)options
(:list
) (required)prompt
(:string
) (required)
Callbacks
The list of options for the select filter.
The select's default option.