Skip to content

Support default values for filters #90

Description

@sevenseacat

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":

  1. First visit (no URL params): Apply defaults internally, keep URL clean
  2. User changes any filter: Push full filter state to URL (their change + any defaults still active)
  3. User clears all filters: Remove URL params, defaults do NOT reapply
  4. 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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestplannedTriaged and on the roadmap — no release committed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions