Module: Datagrid::Ordering

Included in:
Base
Defined in:
lib/datagrid/ordering.rb

Overview

Module adds support for ordering by defined columns for Datagrid.

Instance Method Summary collapse

Instance Method Details

#order_columnDatagrid::Columns::Column?

Returns a column definition that is currently used to order assets.

Examples:

class MyGrid
  scope { Model }
  column(:id)
  column(:name)
end
MyGrid.new(order: "name").order_column # => #<Column name: "name", ...>

Returns:



50
51
52
# File 'lib/datagrid/ordering.rb', line 50

def order_column
  order ? column_by_name(order) : nil
end

#ordered_by?(column, desc = nil) ⇒ Boolean

Returns true if given grid is ordered by given column.

Parameters:

  • column (String, Datagrid::Columns::Column)
  • desc (nil, Boolean) (defaults to: nil)

    confirm order direction as well if specified

Returns:

  • (Boolean)

    true if given grid is ordered by given column.



57
58
59
60
# File 'lib/datagrid/ordering.rb', line 57

def ordered_by?(column, desc = nil)
  order_column == column_by_name(column) &&
    (desc.nil? || (desc ? descending? : !descending?))
end