class Presentation::Grid::Field
Attributes
sort_name[R]
Public Instance Methods
is_sorted?(request)
click to toggle source
is this field sorted in the given request?
# File lib/presentation/grid.rb, line 79 def is_sorted?(request) @is_sorted ||= if sortable? and sorting = request.query_parameters["sort"] and sorting[sort_name] sorting[sort_name].to_s.match(/desc/i) ? 'desc' : 'asc' else false end end
sortable=(val)
click to toggle source
Defines how this field sorts. This means two things:
1. whether it sorts 2. what name it uses to sort
Examples:
# The field is sortable and assumes the sort_name of "first_name". # This is the default. Field.new(:sortable => true, :name => "First Name") # The field is sortable and assumes the sort_name of "first". Field.new(:sortable => 'first', :name => 'First Name') # The field is unsortable. Field.new(:sortable => false)
# File lib/presentation/grid.rb, line 60 def sortable=(val) @sort_name = case val when TrueClass, FalseClass, NilClass val else val.to_s end end
sortable?()
click to toggle source
if the field is sortable at all
# File lib/presentation/grid.rb, line 70 def sortable? self.sortable = Presenting::Defaults.grid_is_sortable unless defined? @sort_name self.sortable = self.id if @sort_name == true !@sort_name.blank? end
sorted_url(request)
click to toggle source
for the view – modifies the current request such that it would sort this field.
# File lib/presentation/grid.rb, line 88 def sorted_url(request) if current_direction = is_sorted?(request) next_direction = current_direction == 'desc' ? 'asc' : 'desc' else next_direction = 'desc' end request.path + '?' + request.query_parameters.merge("sort" => {sort_name => next_direction}).to_param end