bogdan / datagrid

Gem to create tables grids with sortable columns and filters
MIT License
1.02k stars 115 forks source link

Drill Down Filters #229

Closed benphelps closed 7 years ago

benphelps commented 7 years ago

So I worked out a way to build drill down filters and figured it might be useful to someone else. I couldn't find anything in the repo about this so I'll post it here. Perhaps it better fits in a Wiki page, let me know.

filter :foobar, :enum, select: proc { |grid|
  # This takes the assets scope, or filtered scope, removes the limit and offset (basically pagination)
  # so that you can use it to build your filter
  grid.assets.unscope(:limit).unscope(:offset).do_stuff
} do |value, scope|
  scope.where(foobar: value)
end

This allows you to use the filter scope (from existing selections) but not limit the scope to results on the current page. With this you can build filters that themselves are built from filtered values.

bogdan commented 7 years ago

This is an interesting use case. I never encountered something like that myself. You may add that to wiki with a more real use case so that people can understand the context.

kirantpatil commented 7 years ago

@benphelps, can you please share screenshot of how does it looks ?

kirantpatil commented 7 years ago

@benphelps, any updates to wiki ?