Method: Datagrid::Columns::ClassMethods#column
- Defined in:
- lib/datagrid/columns.rb
#column(name, query = nil, **options, &block) ⇒ Datagrid::Columns::Column
Defines a new datagrid column
Options Hash (**options):
-
html
(Boolean, String)
—
Determines if the column should be present in the HTML table and how it is formatted.
-
order
(String, Array<Symbol>, Proc)
—
Determines if the column can be sortable and specifies the ORM ordering method. Example:
"created_at, id"for ActiveRecord,[:created_at, :id]for Mongoid. Can be a Proc accepting a scope argument and returning a scope with applied order -
order_desc
(String, Array<Symbol>, Proc)
—
Specifies a descending order for the column. See
orderoption for context. Used when:ordercannot be easily reversed by the ORM. -
order_by_value
(Boolean, Proc)
—
Enables Ruby-level ordering for the column. Warning: Sorting large datasets in Ruby is not recommended. If
true, Datagrid orders by the column value. If a block is provided, Datagrid orders by the block's return value. -
mandatory
(Boolean)
—
If
true, the column will never be hidden by the#column_namesselection. -
before
(Symbol)
—
Places the column before the specified column when determining order.
-
after
(Symbol)
—
Places the column after the specified column when determining order.
-
if
(Symbol, Proc)
—
conditions when a column is available, can be a method name or a proc with grid argument returning
Boolean. -
unless
(Symbol, Proc)
—
conditions when a column is not available, can be a method name or a proc with grid argument returning
Boolean. -
preload
(Symbol, Array<Symbol>)
—
Specifies associations to preload for the column within the scope.
-
tag_options
(Hash)
—
Specifies HTML attributes for the
<td>or<th>of the column. Example:{ class: "content-align-right", "data-group": "statistics" }.
Parameters:
-
column name
-
(defaults to: nil)
a string representing the query to select this column (supports only ActiveRecord)
-
proc to calculate a column value
-
a customizable set of options
Returns:
289 290 291 |
# File 'lib/datagrid/columns.rb', line 289 def column(name, query = nil, **options, &block) define_column(columns_array, name, query, **options, &block) end |