Module: Datagrid::Helper
- Defined in:
- lib/datagrid/helper.rb
Defined Under Namespace
Classes: HtmlRow
Instance Method Summary collapse
-
#datagrid_form_for(grid, options = {}) ⇒ Object
Renders HTML for for grid with all filters inputs and lables defined in it.
-
#datagrid_format_value(grid, column_name, model) ⇒ Object
:nodoc:.
-
#datagrid_header(grid, options = {}) ⇒ Object
Renders HTML table header for given grid instance using columns defined in it.
-
#datagrid_order_for(grid, column, options = {}) ⇒ Object
Renders ordering controls for the given column name.
-
#datagrid_row(grid, asset, &block) ⇒ Object
Provides access to datagrid columns data.
-
#datagrid_rows(grid, assets, options = {}) ⇒ Object
Renders HTML table rows using given grid definition using columns defined in it.
-
#datagrid_table(grid, *args) ⇒ Object
Renders html table with columns defined in grid class.
-
#datagrid_value(grid, column_name, model) ⇒ Object
Returns individual cell value from the given grid, column name and model Allows to render custom HTML layout for grid data.
Instance Method Details
#datagrid_form_for(grid, options = {}) ⇒ Object
Renders HTML for for grid with all filters inputs and lables defined in it
Supported options:
-
:partials
- Path for form partial lookup. Default: ‘datagrid’. -
All options supported by Rails
form_for
helper
88 89 90 |
# File 'lib/datagrid/helper.rb', line 88 def datagrid_form_for(grid, = {}) datagrid_renderer.form_for(grid, ) end |
#datagrid_format_value(grid, column_name, model) ⇒ Object
:nodoc:
20 21 22 |
# File 'lib/datagrid/helper.rb', line 20 def datagrid_format_value(grid, column_name, model) #:nodoc: datagrid_value(grid, column_name, model) end |
#datagrid_header(grid, options = {}) ⇒ Object
Renders HTML table header for given grid instance using columns defined in it
Supported options:
-
:order
- display ordering controls built-in into header Default: true -
:partials
- Path for partials lookup. Default: ‘datagrid’.
53 54 55 |
# File 'lib/datagrid/helper.rb', line 53 def datagrid_header(grid, = {}) datagrid_renderer.header(grid, ) end |
#datagrid_order_for(grid, column, options = {}) ⇒ Object
Renders ordering controls for the given column name
Supported options:
-
:partials
- Path for partials lookup. Default: ‘datagrid’.
77 78 79 |
# File 'lib/datagrid/helper.rb', line 77 def datagrid_order_for(grid, column, = {}) datagrid_renderer.order_for(grid, column, ) end |
#datagrid_row(grid, asset, &block) ⇒ Object
Provides access to datagrid columns data.
# Suppose that <tt>grid</tt> has first_name and last_name columns
<%= datagrid_row(grid, user) do |row| %>
<tr>
<td><%= row.first_name %></td>
<td><%= row.last_name %></td>
</tr>
<% end %>
Used in case you want to build html table completelly manually
103 104 105 106 107 108 109 |
# File 'lib/datagrid/helper.rb', line 103 def datagrid_row(grid, asset, &block) HtmlRow.new(self, grid, asset).tap do |row| if block_given? return capture(row, &block) end end end |
#datagrid_rows(grid, assets, options = {}) ⇒ Object
Renders HTML table rows using given grid definition using columns defined in it
Supported options:
-
:columns
- Array of column names to display. Used in case when same grid class is used in different places and needs different columns. Default: all defined columns. -
:partials
- Path for partials lookup. Default: ‘datagrid’.
67 68 69 |
# File 'lib/datagrid/helper.rb', line 67 def datagrid_rows(grid, assets, = {}) datagrid_renderer.rows(grid, assets, ) end |
#datagrid_table(grid, *args) ⇒ Object
Renders html table with columns defined in grid class. In the most common used you need to pass paginated collection to datagrid table because datagrid do not have pagination compatibilities:
assets = grid.assets.page(params[:page])
datagrid_table(grid, assets, )
Supported options:
-
:html
- hash of attributes for <table> tag -
:order
- If false do not generate ordering controlls. Default: true. -
:columns
- Array of column names to display. Used in case when same grid class is used in different places and needs different columns. Default: all defined columns. -
:partials
- Path for partials lookup. Default: ‘datagrid’.
41 42 43 |
# File 'lib/datagrid/helper.rb', line 41 def datagrid_table(grid, *args) datagrid_renderer.table(grid, *args) end |
#datagrid_value(grid, column_name, model) ⇒ Object
Returns individual cell value from the given grid, column name and model Allows to render custom HTML layout for grid data
<ul>
<% @grid.columns.each do |column|
<li><%= column.header %>: <%= datagrid_value(@grid, column.name, @resource %></li>
<% end %>
</ul>
16 17 18 |
# File 'lib/datagrid/helper.rb', line 16 def datagrid_value(grid, column_name, model) datagrid_renderer.format_value(grid, column_name, model) end |