diff --git a/docs/3.0/dynamic-filters.md b/docs/3.0/dynamic-filters.md index fb3d345f..7ca2ac45 100644 --- a/docs/3.0/dynamic-filters.md +++ b/docs/3.0/dynamic-filters.md @@ -7,12 +7,12 @@ license: advanced The Dynamic filters make it so easy to add multiple, composable, and dynamic filters to the view. -The only thing you need to do is add the `filterable: true` attribute to the fields you need to filter through. +The first thing you need to do is add the `filterable: true` attribute to the fields you need to filter through. We use `ransack` behind the scenes so it's essential to configure the `ransackable_attributes` list to ensure that every filterable field is incorporated within it. -```ruby{6-8} -class Avo::Resources::Project < Avo::BaseResource - self.title = :name +:::code-group +```ruby{4-6} [Fields] +class Avo::Resources::Project < Avo::BaseResource def fields field :name, as: :text field :status, as: :status, filterable: true @@ -22,6 +22,24 @@ class Avo::Resources::Project < Avo::BaseResource end ``` +```ruby{3,9,12} [Ransackable attributes] +class Project < ApplicationRecord + def self.ransackable_attributes(auth_object = nil) + ["status", "stage", "country"] + end +end + +# Or + +# https://activerecord-hackery.github.io/ransack/going-further/other-notes/#authorization-allowlistingdenylisting +class Project < ApplicationRecord + def self.ransackable_attributes(auth_object = nil) + super + end +end +``` +::: + This will make Avo add this new "Filters" button to the view of your resource. When the user clicks the button, a new filters bar will appear below enabling them to add filters based on the attributes you marked as filterable.