LiveTable.Boolean (live_table v0.2.0)
View SourceA module for handling boolean (checkbox) filters in LiveTable.
This module provides functionality for creating and managing boolean filters implemented as checkboxes in the LiveTable interface. It's designed to handle simple true/false filtering scenarios with customizable options and conditions.
Options
The boolean filter accepts the following options:
:label
- The text label displayed next to the checkbox:condition
- The Ecto query condition to be applied when the checkbox is checked (a dynamic query):class
- Optional CSS classes for the checkbox
Examples
# Creating a basic boolean filter for active status
Boolean.new(:active, "active_filter", %{
label: "Show Active Only",
condition: dynamic([p], p.active == true)
})
# Creating a boolean filter with a complex condition
Boolean.new(:premium, "premium_filter", %{
label: "Premium Users",
condition: dynamic([p], p.subscription_level == "premium" and p.active == true)
})
Since the condition is a dynamic query, you can give conditions using joined fields as well.
Boolean.new(
:supplier_email,
"supplier",
%{
label: "Email",
condition: dynamic([p, s], s.contact_info == "procurement@autopartsdirect.com")
}
)
Note: Remember to use aliases in the same order you defined your fields.