{"id":13747311,"url":"https://github.com/holyketzer/activeadmin-ajax_filter","last_synced_at":"2025-05-16T03:03:28.313Z","repository":{"id":3714188,"uuid":"50670633","full_name":"holyketzer/activeadmin-ajax_filter","owner":"holyketzer","description":"AJAX filters for ActiveAdmin","archived":false,"fork":false,"pushed_at":"2024-11-29T14:14:29.000Z","size":172,"stargazers_count":87,"open_issues_count":3,"forks_count":22,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T04:26:01.039Z","etag":null,"topics":["activeadmin","ajax","ajax-filters","ajax-input","filter","input"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/holyketzer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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}},"created_at":"2016-01-29T15:21:20.000Z","updated_at":"2024-12-17T07:51:30.000Z","dependencies_parsed_at":"2025-01-28T22:41:23.283Z","dependency_job_id":null,"html_url":"https://github.com/holyketzer/activeadmin-ajax_filter","commit_stats":{"total_commits":60,"total_committers":11,"mean_commits":5.454545454545454,"dds":0.5,"last_synced_commit":"c833e62805476723bf816761b87a44d6110020f8"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holyketzer%2Factiveadmin-ajax_filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holyketzer%2Factiveadmin-ajax_filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holyketzer%2Factiveadmin-ajax_filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holyketzer%2Factiveadmin-ajax_filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/holyketzer","download_url":"https://codeload.github.com/holyketzer/activeadmin-ajax_filter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254459083,"owners_count":22074604,"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":["activeadmin","ajax","ajax-filters","ajax-input","filter","input"],"created_at":"2024-08-03T06:01:24.689Z","updated_at":"2025-05-16T03:03:24.464Z","avatar_url":"https://github.com/holyketzer.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"[![Gem Version](https://badge.fury.io/rb/activeadmin-ajax_filter.svg)](https://badge.fury.io/rb/activeadmin-ajax_filter)\n[![Build Status](https://github.com/holyketzer/activeadmin-ajax_filter/actions/workflows/main.yaml/badge.svg)](https://github.com/holyketzer/activeadmin-ajax_filter/actions)\n[![Code Climate](https://codeclimate.com/github/holyketzer/activeadmin-ajax_filter/badges/gpa.svg)](https://codeclimate.com/github/holyketzer/activeadmin-ajax_filter)\n\n# Activeadmin::AjaxFilter\n\nThis gem extends ActiveAdmin so that your can use filters with AJAX-powered input.\n\n\u003cimg src=\"https://user-images.githubusercontent.com/987021/53289159-709c5000-37a3-11e9-97d5-0e61d2759b3c.gif\" width=\"276\" alt=\"ActiveAdmin AJAX Filter input\"/\u003e\n\n\n## Prerequisites and notes\n\nThis extension assumes that you're using [Active Admin](https://github.com/activeadmin/activeadmin) with [Ransack](https://github.com/activerecord-hackery/ransack). And for AJAX input it uses [selectize-rails](https://github.com/manuelvanrijn/selectize-rails)\n\nVersions:\n* `0.7.0` - Rails 7, minimum Ruby version `2.7`\n* `0.6.0` - Rails 6, minimum Ruby version `2.7`\n* `0.5.0` - Rails 5, minimum Ruby version `2.5`\n* `0.4.5` - could break you build due to issue with `sprockets` version major update, now it's yanked, use `0.4.6` instead. If you on `sprockets \u003e= 4` and `rails \u003e= 5` use version `0.5.0`\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'activeadmin-ajax_filter'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install activeadmin-ajax_filter\n\n## Usage\n\nInclude this line in your JavaScript code (active_admin.js)\n\n```js\n//= require selectize\n//= require activeadmin-ajax_filter\n```\n\nInclude this line in your CSS code (active_admin.scss)\n\n```scss\n@import \"selectize\";\n@import \"selectize.default\";\n@import \"activeadmin-ajax_filter\";\n```\n\nInclude `ActiveAdmin::AjaxFilter` module to the ActiveAdmin relation resource for which you want to support filtering and add `ajax_select` filter to main resource. For example:\n\n```ruby\n# Relation-resource\nActiveAdmin.register User do\n  include ActiveAdmin::AjaxFilter\n  # ...\nend\n\n# Main resource\n# As a filter\nActiveAdmin.register Invoice do\n  filter :user, as: :ajax_select, data: { \n    url: :filter_admin_users_path, \n    search_fields: [:email, :customer_uid], \n    limit: 7,\n  }\n  # ...\nend\n\n# As a form input\nActiveAdmin.register Invoice do\n  form do |f|\n    f.input :language # used by ajax_search_fields\n    f.input :user, as: :ajax_select, data: { \n      url: filter_admin_users_path,\n      search_fields: [:name], \n      static_ransack: { active_eq: true }, \n      ajax_search_fields: [:language_id],\n    }\n    # ...\n  end\nend\n```\n\nYou can use next parameters in `data` hash:\n\n* `search_fields` - fields by which AJAX search will be performed, **required**\n* `display_fields` - fields which will be displayed in drop down list during search, first field will be displayed for selected option\n* `limit` - count of the items which will be requested by AJAX, by default `5`\n* `value_field` - value field for html select element, by default `id`\n* `ordering` - sort string like `email ASC, customer_uid DESC`, by default it uses first value of `search_fields` with `ASC` direction\n* `ransack` - ransack query which will be applied, by default it's builded from `search_fields` with `or` and `contains` clauses, e.g.: `email_or_customer_uid_cont`\n* `url` - url for AJAX query by default is builded from field name. For inputs you can use url helpers, but on filters level url helpers isn't available, so if you need them you can pass symbols and it will be evaluated as url path (e.g. `:filter_admin_users_path`). `String` with relative path (like `/admin/users/filter`) can be used for both inputs and filters.\n* `ajax_search_fields` - array of field names. `ajax_select` input depends on `ajax_search_fields` values: e.g. you can scope user by languages.\n* `static_ransack` - hash of ransack predicates which will be applied statically and independently from current input field value\n* `min_chars_count_to_request` - minimal count of chars in the input field to make an AJAX request\n* `placeholder` - input field placeholder.\n* `close_after_select` - close search results drop-down after selected a value. Default is `false`.\n\n### Filter by belongs_to relation fields\n\n```ruby\nclass Patient \u003c ApplicationRecord\n  belongs_to :user\n  # ...\nend\n\nf.input :patient, as: :ajax_select, collection: [], data: {\n  display_fields: ['id', 'user.name'],\n  search_fields: ['user.name'],\n  ordering: 'id ASC',\n  url: :filter_admin_patients_path\n}\n```\nOrdering by related fields doesn't work, e.g. this will not work: `ordering: 'user.name ASC'`\n\n\n## Caveats\n\n### Ransack _cont on Integer column\n\nDue to issue with Ransack and Postgres it's not possbile to make searches like `id_cont` because `id` is a `Integer` type (more here https://github.com/activerecord-hackery/ransack/issues/85)\n\nThe way to handle it find with another predicate like:\n\n```ruby\nfilter :user_id, as: :ajax_select, collection: [], data: {\n    url: '/admin/users/filter',\n    display_fields: [:full_name, :phone],\n    ransack: 'id_eq', # !!! predicate is ovewritten to `eq` by default it's `cont`\n    search_fields: ['id'],\n  }\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/holyketzer/activeadmin-ajax_filter. This project is intended to be a safe, welcoming space for collaboration.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fholyketzer%2Factiveadmin-ajax_filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fholyketzer%2Factiveadmin-ajax_filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fholyketzer%2Factiveadmin-ajax_filter/lists"}