class Wice::WiceGrid
Main class responsible for keeping the state of the grid, building an ActiveRelation, and running queries
Public Instance Methods
Returns the list of objects browsable through all pages with the current filters. Should only be called after the grid
helper.
# File lib/wice_grid.rb, line 537 def all_pages_records raise WiceGridException.new('all_pages_records can only be called only after the grid view helper') unless self.view_helper_finished resultset_without_paging_with_user_filters end
Apply the sort_by option to the results.
# File lib/wice_grid.rb, line 344 def apply_sort_by(relation) active_sort_by = nil @renderer.find_one_for(->(c) {c.attribute == @status[:order]}) {|r| active_sort_by = r.sort_by} return relation if !active_sort_by relation = relation.sort_by(&active_sort_by) relation = relation.reverse if @status[:order_direction] == 'desc' return relation end
Returns the list of objects displayed on current page. Should only be called after the grid
helper.
# File lib/wice_grid.rb, line 543 def current_page_records raise WiceGridException.new('current_page_records can only be called only after the grid view helper') unless self.view_helper_finished @resultset end
Returns true if the current results are ordered by the passed column.
# File lib/wice_grid.rb, line 415 def ordered_by?(column) return nil if @status[:order].blank? if column.main_table && ! @status[:order].index('.') || column.table_alias_or_table_name.nil? @status[:order] == column.attribute else @status[:order] == column.table_alias_or_table_name + '.' + column.attribute end end
A block executed from within the plugin to process records of the current page. The argument to the callback is the array of the records. See the README for more details.
# File lib/wice_grid.rb, line 179 def with_paginated_resultset(&callback) @options[:with_paginated_resultset] = callback end
A block executed from within the plugin to process all records browsable through all pages with the current filters. The argument to the callback is a lambda object which returns the list of records when called. See the README for the explanation.
# File lib/wice_grid.rb, line 186 def with_resultset(&callback) @options[:with_resultset] = callback end
Protected Instance Methods
Returns tablename.columnname for the passed column reference.
# File lib/wice_grid.rb, line 594 def complete_column_name(col_name) return col_name if col_name.index('.') # already has a table name return "#{@klass.table_name}.#{col_name}" end
If a custom order has been configured, gets the column/function to be ordered by. If no custom order, returns nil.
# File lib/wice_grid.rb, line 565 def get_custom_order_reference # TODO Do we need to distinguish between no custom order and a custom order that defines no ordering? Both return nil. fully_qualified_column_name = complete_column_name(@status[:order]) custom_order = if @options[:custom_order].key?(fully_qualified_column_name) @options[:custom_order][fully_qualified_column_name] else if view_column = @renderer[fully_qualified_column_name] view_column.custom_order end end return custom_order if custom_order.nil? || custom_order.is_a?(Arel::Attributes::Attribute) return custom_order.gsub(/\?/, fully_qualified_column_name) if custom_order.is_a?(String) return custom_order.call(fully_qualified_column_name) if custom_order.is_a?(Proc) raise WiceGridArgumentError.new("invalid custom order #{custom_order.inspect}") end