{"id":29820804,"url":"https://github.com/cpursley/livefilter","last_synced_at":"2025-07-28T23:03:33.320Z","repository":{"id":304411507,"uuid":"1018736946","full_name":"cpursley/livefilter","owner":"cpursley","description":"A flexible and composable filtering library for Phoenix LiveView applications","archived":false,"fork":false,"pushed_at":"2025-07-20T20:28:41.000Z","size":99,"stargazers_count":10,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-20T21:22:09.933Z","etag":null,"topics":["admin-dashboard","elixir","liveview"],"latest_commit_sha":null,"homepage":"https://livefilter.fly.dev/todos","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cpursley.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-12T23:33:08.000Z","updated_at":"2025-07-20T20:28:45.000Z","dependencies_parsed_at":"2025-07-20T21:22:59.716Z","dependency_job_id":null,"html_url":"https://github.com/cpursley/livefilter","commit_stats":null,"previous_names":["cpursley/livefilter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cpursley/livefilter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpursley%2Flivefilter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpursley%2Flivefilter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpursley%2Flivefilter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpursley%2Flivefilter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cpursley","download_url":"https://codeload.github.com/cpursley/livefilter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpursley%2Flivefilter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266224674,"owners_count":23895458,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["admin-dashboard","elixir","liveview"],"created_at":"2025-07-28T23:01:53.802Z","updated_at":"2025-07-28T23:03:33.314Z","avatar_url":"https://github.com/cpursley.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LiveFilter\n\nA flexible and composable filtering library for Phoenix LiveView applications, inspired by Linear, Notion and Airtable. Provides filtering, sorting, and pagination with clean URL state management and a modern UI built on [SaladUI](https://salad-storybook.fly.dev/) and inspired by [shadcn/ui data tables](https://tablecn.com/).\n\n[![Hex.pm](https://img.shields.io/hexpm/v/livefilter.svg)](https://hex.pm/packages/livefilter)\n[![Documentation](https://img.shields.io/badge/documentation-hexdocs-blue.svg)](https://hexdocs.pm/livefilter)\n\n**Demo**: [https://livefilter.fly.dev](https://livefilter.fly.dev/) - source: [https://github.com/cpursley/livefilter-demo](https://github.com/cpursley/livefilter-demo)\n\n## Features\n\n- Filter operators for all data types (string, numeric, boolean, date, enum, array)\n- URL state management with shareable filter links\n- Autogeneration of database-efficient queries\n- Sorting and column management\n- Components built on shadcn-inspired [SaladUI](https://salad-storybook.fly.dev/)\n\n## Installation\n\nAdd to your `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:livefilter, \"~\u003e 0.1.7\"}\n  ]\nend\n```\n\nInstall JavaScript assets:\n\n```bash\nmix live_filter.install.assets\n```\n\nAdd to your `app.js`:\n\n```javascript\nimport LiveFilter from \"./hooks/live_filter/live_filter\"\n\nlet liveSocket = new LiveSocket(\"/live\", Socket, {\n  hooks: { LiveFilter }\n})\n```\n\n## Basic Usage\n\n### 1. Minimal Setup\n\n```elixir\ndefmodule MyAppWeb.ProductLive do\n  use MyAppWeb, :live_view\n  alias LiveFilter.{Filter, FilterGroup, QueryBuilder}\n\n  def mount(_params, _session, socket) do\n    {:ok, assign(socket, :products, load_products())}\n  end\n\n  defp load_products(filter_group \\\\ %FilterGroup{}) do\n    from(p in Product)\n    |\u003e QueryBuilder.build_query(filter_group)\n    |\u003e Repo.all()\n  end\nend\n```\n\n### 2. URL-Persisted Filters\n\n```elixir\ndefmodule MyAppWeb.ProductLive do\n  use MyAppWeb, :live_view\n  use LiveFilter.Mountable  # Adds filter helpers\n\n  def mount(_params, _session, socket) do\n    socket = mount_filters(socket)\n    {:ok, assign(socket, :products, [])}\n  end\n\n  def handle_params(params, _url, socket) do\n    socket = handle_filter_params(socket, params)\n    {:noreply, assign(socket, :products, load_products(socket.assigns.filter_group))}\n  end\n\n  defp load_products(filter_group) do\n    from(p in Product)\n    |\u003e QueryBuilder.build_query(filter_group)\n    |\u003e Repo.all()\n  end\nend\n```\n\n## Advanced Example\n\nHere's a complete implementation with UI components (similar to our [demo app](https://livefilter.fly.dev/)):\n\n```elixir\ndefmodule MyAppWeb.TodoLive do\n  use MyAppWeb, :live_view\n  use LiveFilter.Mountable\n\n  def mount(_params, _session, socket) do\n    socket = \n      socket\n      |\u003e mount_filters(registry: field_registry())\n      |\u003e assign(:todos, [])\n    \n    {:ok, socket}\n  end\n\n  def handle_params(params, _url, socket) do\n    socket = handle_filter_params(socket, params)\n    {:noreply, assign(socket, :todos, load_todos(socket.assigns.filter_group))}\n  end\n\n  def render(assigns) do\n    ~H\"\"\"\n    \u003cdiv class=\"space-y-4\"\u003e\n      \u003c!-- Search and quick filters --\u003e\n      \u003cdiv class=\"flex gap-4\"\u003e\n        \u003cform phx-change=\"search\" class=\"flex-1\"\u003e\n          \u003cinput name=\"q\" value={@search} placeholder=\"Search todos...\" /\u003e\n        \u003c/form\u003e\n        \n        \u003c.live_component \n          module={LiveFilter.Components.SearchSelect}\n          id=\"status-filter\"\n          field={:status}\n          value={get_filter_value(@filter_group, :status)}\n          options={[\n            {\"pending\", \"Pending\"},\n            {\"in_progress\", \"In Progress\"}, \n            {\"completed\", \"Completed\"}\n          ]}\n        /\u003e\n      \u003c/div\u003e\n\n      \u003c!-- Advanced filter builder --\u003e\n      \u003c.live_component\n        module={LiveFilter.Components.FilterBuilder}\n        id=\"filter-builder\"\n        filter_group={@filter_group}\n        field_options={field_options()}\n      /\u003e\n\n      \u003c!-- Results table --\u003e\n      \u003ctable\u003e\n        \u003cthead\u003e\n          \u003ctr\u003e\n            \u003c.live_component \n              module={LiveFilter.Components.SortableHeader}\n              id=\"sort-title\"\n              field={:title}\n              label=\"Title\"\n              current_sort={@current_sort}\n            /\u003e\n            \u003cth\u003eStatus\u003c/th\u003e\n            \u003cth\u003eDue Date\u003c/th\u003e\n          \u003c/tr\u003e\n        \u003c/thead\u003e\n        \u003ctbody\u003e\n          \u003ctr :for={todo \u003c- @todos}\u003e\n            \u003ctd\u003e\u003c%= todo.title %\u003e\u003c/td\u003e\n            \u003ctd\u003e\u003c%= todo.status %\u003e\u003c/td\u003e\n            \u003ctd\u003e\u003c%= todo.due_date %\u003e\u003c/td\u003e\n          \u003c/tr\u003e\n        \u003c/tbody\u003e\n      \u003c/table\u003e\n    \u003c/div\u003e\n    \"\"\"\n  end\n\n  def handle_event(\"search\", %{\"q\" =\u003e query}, socket) do\n    filter = %Filter{field: :title, operator: :contains, value: query, type: :string}\n    filter_group = %FilterGroup{filters: [filter]}\n    socket = apply_filters_and_reload(socket, filter_group)\n    {:noreply, assign(socket, :search, query)}\n  end\n\n  defp field_registry do\n    LiveFilter.FieldRegistry.new()\n    |\u003e LiveFilter.FieldRegistry.put(:title, :string, \"Title\")\n    |\u003e LiveFilter.FieldRegistry.put(:status, :enum, \"Status\", \n         options: [{\"pending\", \"Pending\"}, {\"in_progress\", \"In Progress\"}, {\"completed\", \"Completed\"}])\n    |\u003e LiveFilter.FieldRegistry.put(:due_date, :date, \"Due Date\")\n    |\u003e LiveFilter.FieldRegistry.put(:tags, :array, \"Tags\")\n  end\n\n  defp load_todos(filter_group) do\n    from(t in Todo)\n    |\u003e QueryBuilder.build_query(filter_group)\n    |\u003e QueryBuilder.apply_sort(socket.assigns.current_sort)\n    |\u003e Repo.all()\n  end\nend\n```\n\n## Documentation\n\n- [API Documentation](https://hexdocs.pm/livefilter)\n- [Demo Application](https://github.com/cpursley/livefilter-demo)\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcpursley%2Flivefilter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcpursley%2Flivefilter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcpursley%2Flivefilter/lists"}