TernaryFilter
Three states: all, yes, no. By default for a boolean column;
nullable() turns it into “set / not set”.
use Anvil\Collection\Filters\TernaryFilter;
TernaryFilter::make('newsletter'),TernaryFilter::make('is_active')->label('Active')->trueLabel('Active')->falseLabel('Inactive'),TernaryFilter::make('ended')->column('ended_at')->nullable()->trueLabel('Ended')->falseLabel('Running'),Options
Section titled “Options”| Option | Effect | Default |
|---|---|---|
nullable() |
“set / not set” instead of yes / no | yes / no |
trueLabel('…') |
label of the yes state | “Yes” |
falseLabel('…') |
label of the no state | “No” |
Plus label() and column().
Control
Section titled “Control”A select “Newsletter: All” with the two labels.
| State | Boolean column | nullable() |
|---|---|---|
| yes | column = 1 |
column IS NOT NULL |
| no | column = 0 OR column IS NULL |
column IS NULL |
| all | no condition | no condition |
nullable() suits columns that are set when something happened:
ended_at, approved_by, deleted_reason.
Saved views, presets and API
Section titled “Saved views, presets and API”'1' for yes, '0' for no. API: filter[newsletter]=1.