Description
Allow filters to specify default values that are applied on initial page load. This is useful for common scenarios like showing only active records by default.
Proposed API
<!-- Boolean with default -->
<:col field="active" filter={[type: :boolean, default: true]} />
<!-- Select with default -->
<:col field="status" filter={[type: :select, default: "active", options: [...]]} />
<!-- Multi-select with default -->
<:col field="tags" filter={[type: :multi_select, default: ["featured"], options: [...]]} />
<!-- Number range with default -->
<:col field="price" filter={[type: :number_range, default: %{min: 0, max: 100}]} />
<!-- Date range with default -->
<:col field="created_at" filter={[type: :date_range, default: %{from: ~D[2024-01-01]}]} />
URL Sync Behavior
When URL sync is enabled, defaults need special handling to distinguish "first visit" from "user cleared all filters":
- First visit (no URL params): Apply defaults internally, keep URL clean
- User changes any filter: Push full filter state to URL (their change + any defaults still active)
- User clears all filters: Remove URL params, defaults do NOT reapply
- Someone visits clean URL: Fresh mount, defaults apply (first visit experience)
Implementation uses a defaults_applied flag to track whether we're past the initial load.
Design Decisions
- "Clear all" clears to empty, not back to defaults (defaults are just initial state)
- Defaults count as active filters in the filter count badge
- Invalid defaults are silently ignored (no validation errors)
Description
Allow filters to specify default values that are applied on initial page load. This is useful for common scenarios like showing only active records by default.
Proposed API
URL Sync Behavior
When URL sync is enabled, defaults need special handling to distinguish "first visit" from "user cleared all filters":
Implementation uses a
defaults_appliedflag to track whether we're past the initial load.Design Decisions