bogdan / datagrid

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

Column Search with drop down based on Column Selection #281

Closed trselva closed 4 years ago

trselva commented 4 years ago

Is it possible to have a drop down (:enum) of distinct values for column search based on the column selection. I tried something as below. But it did not worked.

filter(:column_selection, :enum, select: :columns_select, dummy: true)
filter(:column_search, :enum, select: :columnvalues_select, dummy: true) do |value, scope, grid|
  if (grid.column_selection)
    scope.where(grid.column_selection => value)
  end
end

def columns_select
  columns.map do |column|
    [column.header, column.name]
  end
end

def columnvalues_select
  columns do |column, grid|
    if (grid.column_selection)
      if grid.column_selection == column.header
        colvalues = Countrytable.select(:"#{column.name}").order("#{column.name}").distinct.all.map(&:"#{column.name}")
      end
    end
  end
end

Also How to refresh or reload column search on change in column selection without page reloading (without form submission)?

trselva commented 4 years ago

Please update whether it is feasible to do with datagrid.

bogdan commented 4 years ago

I have no idea what are you trying to build. Please build the interface you want with a tool like https://jsfiddle.net/ and share it with me.

bogdan commented 4 years ago

No feedback, closing