Skip to content

Commit

Permalink
Merge pull request #117 from avo-hq/improvement/dynamic_filters
Browse files Browse the repository at this point in the history
improvement: dynamic filters
  • Loading branch information
Paul-Bob authored Oct 11, 2023
2 parents d444e96 + c424cba commit 9772fe0
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions docs/3.0/dynamic-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ license: advanced

The Dynamic filters make it so easy to add multiple, composable, and dynamic filters to the <Index /> 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
Expand All @@ -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 <Index /> 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.
Expand Down

0 comments on commit 9772fe0

Please sign in to comment.