Parameters
- header
- table
- #{scope.field_name}-heading
- #{scope.field_name}-heading-link
- up-arrow
- down-arrow
- empty-message
- page-nav
Attributes
All attributes supported by <table> and <with-fields> are supported.
AJAX attributes are passed through to the sort links and the search form.
sort-field: defaults to @sort_field, if that is available. parse_sort_params sets this variable
sort-direction: ‘asc’ or ‘dec’. defaults to @sort_direction, if that is available. parse_sort_params sets this variable
sort-columns: a hash that allow you to map fields to sortable columns. The default is {“this” => “name”} (or whatever column that has the :name option set on it).
Show Source
<def attrs='sort-field, sort-direction, sort-columns' tag='table-plus'>
<% sort_field ||= @sort_field; sort_direction ||= @sort_direction; sort_columns ||= {} %>
<% sort_columns['this'] ||= this.try.member_class.try.name_attribute %>
<% ajax_attrs, attributes = attributes.partition_hash(HoboRapidHelper::AJAX_ATTRS) %>
<div class='table-plus' merge-attrs='&attributes - attrs_for(:with_fields) - attrs_for(:table)'>
<div class='header' param='header'>
<div class='search'>
<search-filter merge-attrs='&ajax_attrs' param/>
</div>
</div>
<table merge-attrs='&attributes & (attrs_for(:table) + attrs_for(:with_fields))' param empty merge-params>
<field-heading-row:>
<with-field-names merge-attrs='&all_attributes & attrs_for(:with_fields)'>
<% col = sort_columns[scope.field_path] || scope.field_path
sort = sort_field == col && sort_direction == 'asc' ?
"-#{col}" : col
sort_url = url_for_page_path(query_parameters_filtered('skip' => 'page').merge(:sort => sort))
col_heading_name = this.member_class.try.human_attribute_name(scope.field_name, :default=> scope.field_name.titleize) %>
<th param='#{scope.field_name}-heading'>
<a href='&sort_url' class='column-sort' param='#{scope.field_name}-heading-link' merge-attrs='&ajax_attrs'><%= col_heading_name %></a>
<if test='&col == sort_field'>
<do param='up-arrow' if='&sort_direction == 'desc''>↑</do>
<do param='down-arrow' if='&sort_direction == 'asc''>↓</do>
</if>
</th>
</with-field-names>
<th class='controls' if='&all_parameters[:controls]'/>
</field-heading-row:>
</table>
<empty-collection-message param='empty-message'/>
<page-nav param merge-attrs='&ajax_attrs' if='&this.respond_to?(:page_count) || this.respond_to?(:total_pages)'/>
</div>
</def>