leikind / wice_grid

A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters
MIT License
537 stars 215 forks source link

Using grid.count or grid.empty? disables all filters #144

Closed originalpete closed 9 years ago

originalpete commented 10 years ago

Using the .empty? method (which just in turn calls .count) before the grid is displayed generates a grid with all filters ignored.

The code below generates a grid which works completely normally, including attribute filters in the view.

class EventsController < AdminController
  def index
    @events_grid = initialize_grid(Event)
  end
end

However, referencing .empty? on the grid renders all the filters inactive. If the index method is changed to look like this:

  def index
    @events_grid = initialize_grid(Event)
    @events_grid.empty?
  end

The grid still displays as normal, but any filters on attributes are ignored (despite the correct URL params being set). It's worth noting that the sort is still preserved.

I suspect that the option :forget_generated_options in wice_grid.rb may be to blame: https://github.com/leikind/wice_grid/blob/rails3/lib/wice_grid.rb#L394

originalpete commented 9 years ago

:+1: