lib/magic_grid/collection.rb in magic_grid-0.11.0 vs lib/magic_grid/collection.rb in magic_grid-0.11.1

- old
+ new

@@ -15,11 +15,11 @@ @post_filters = [] @post_filter_callbacks = [] @paginations = [] end - delegate :map, :count, :to => :collection + delegate :quoted_table_name, :map, :count, :to => :collection attr_accessor :grid attr_reader :current_page, :original_count, :total_pages def self.[](collection, grid) @@ -29,10 +29,14 @@ else Collection.new(collection, grid) end end + def column_names + @collection.table.columns.map {|c| c.name} + end + def quote_column_name(col) @collection.connection.quote_column_name(col.to_s) end def search_using_builtin(collection, q) @@ -73,19 +77,21 @@ def sortable? @collection.respond_to?(:order) end def apply_sort(col, dir) + @reduced_collection = nil @sorts << "#{col} #{dir}" self end def searchable? filterable? or @collection.respond_to? @grid.options[:search_method] end def apply_search(q) + @reduced_collection = nil @searches << q self end def perform_search(collection, q) @@ -99,32 +105,36 @@ @collection.respond_to? :where end def apply_filter(filters = {}) if @collection.respond_to? :where + @reduced_collection = nil @filters << filters end self end def apply_filter_callback(callback) if callback.respond_to? :call + @reduced_collection = nil @filter_callbacks << callback end self end def has_post_filter? @collection.respond_to? :post_filter end def apply_post_filter + @reduced_collection = nil @post_filters << :post_filter self end def apply_pagination(current_page, per_page) if per_page + @reduced_collection = nil @paginations << {:current_page => current_page, :per_page => per_page} end self end