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(report, column_name, model) ⇒ Object
Format an value from datagrid column with given name and for given model.
-
#datagrid_header(grid, options = {}) ⇒ Object
Renders HTML table header for given grid instance using columns defined in it.
-
#datagrid_order_for(grid, column) ⇒ Object
Renders ordering controls for the given column name.
-
#datagrid_row(grid, asset, &block) ⇒ Object
Provides access to datagrid column data.
-
#datagrid_rows(report, assets, options = {}) ⇒ Object
Renders HTML table rows using given grid definition using columns defined in it.
-
#datagrid_table(report, *args) ⇒ Object
Renders html table with columns defined in grid class.
Instance Method Details
#datagrid_form_for(grid, options = {}) ⇒ Object
Renders HTML for for grid with all filters inputs and lables defined in it
56 57 58 |
# File 'lib/datagrid/helper.rb', line 56 def datagrid_form_for(grid, = {}) datagrid_renderer.form_for(grid, ) end |
#datagrid_format_value(report, column_name, model) ⇒ Object
Format an value from datagrid column with given name and for given model
8 9 10 |
# File 'lib/datagrid/helper.rb', line 8 def datagrid_format_value(report, column_name, model) datagrid_renderer.format_value(report, 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
40 41 42 |
# File 'lib/datagrid/helper.rb', line 40 def datagrid_header(grid, = {}) datagrid_renderer.header(grid, ) end |
#datagrid_order_for(grid, column) ⇒ Object
Renders ordering controls for the given column name
51 52 53 |
# File 'lib/datagrid/helper.rb', line 51 def datagrid_order_for(grid, column) datagrid_renderer.order_for(grid, column) end |
#datagrid_row(grid, asset, &block) ⇒ Object
Provides access to datagrid column data.
<%= 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 datagrid table completelly manually
70 71 72 73 74 75 76 |
# File 'lib/datagrid/helper.rb', line 70 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(report, assets, options = {}) ⇒ Object
Renders HTML table rows using given grid definition using columns defined in it
46 47 48 |
# File 'lib/datagrid/helper.rb', line 46 def datagrid_rows(report, assets, = {}) datagrid_renderer.rows(report, assets, ) end |
#datagrid_table(report, *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. -
:cycle- Used as arguments for cycle for each row. Default: false. Example:["odd", "even"]. -
: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.
29 30 31 |
# File 'lib/datagrid/helper.rb', line 29 def datagrid_table(report, *args) datagrid_renderer.table(report, *args) end |