bogdan / datagrid

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

Passing parameters to filter "select" #253

Closed fabriciofreitag closed 5 years ago

fabriciofreitag commented 5 years ago

Is it currently possible to achieve something like this?

MyGrid.new(only_these_foo_ids: [1, 2, 3])

# then in the grid definition:

filter(:foos, :enum, select: proc { Foo.where(id: only_these_foo_ids).pluck(:name, :id) })
bogdan commented 5 years ago

Yes, you can do something like this:

class MyGrid
  attr_accessor :only_these_foo_ids
  filter(:foos, :enum, select: :foo_select)

  def foo_select
    Foo.where(id: only_these_foo_ids).pluck(:name, :id)
  end
end
fabriciofreitag commented 5 years ago

brilliant! thanks!!!!