Module: TableSortable::ViewHelpers
- Defined in:
- lib/table_sortable/view_helpers.rb
Instance Method Summary collapse
- #table_sortable_columns(record, html_options = {}) ⇒ Object
- #table_sortable_headers(html_options = {}) ⇒ Object
- #table_sortable_pager(*args) ⇒ Object
Instance Method Details
#table_sortable_columns(record, html_options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/table_sortable/view_helpers.rb', line 51 def table_sortable_columns(record, = {}) controller.columns.map.with_index do |col, index| value = col.value(record) content = col.content(record) = {} ['data-text'] = value if value != content .merge!() if col.column_partial render file: col.column_partial, locals: {content: content, value: value, source: record, column: col, index: index} else content_tag :td, do content end end end.join.html_safe end |
#table_sortable_headers(html_options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/table_sortable/view_helpers.rb', line 25 def table_sortable_headers( = {}) controller.columns.map.with_index do |col, index| = {} ['data-placeholder'] = col.placeholder if col.placeholder # th_options['data-priority'] = col.sort_priority if col.sort_priority ['data-filter'] = 'false' if col.filter.disabled? ['data-sorter'] = 'false' if col.sorter.disabled? unless col.filter.collection.blank? ['data-filter-options'] = col.filter.collection.to_json end ['data-value'] = col.filter.default_value if col.filter.default_value .merge!() if col.header_partial render file: col.header_partial, locals: {label: col.label, column: col, index: index} else content_tag :th, do col.label end end end.join.html_safe end |
#table_sortable_pager(*args) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/table_sortable/view_helpers.rb', line 4 def table_sortable_pager(*args) = args. pagination_class = [:wrapper_class] || 'pagination' page_display_class = [:page_display_class] || 'pagedisplay' item_wrapper_class = [:item_wrapper_class] item_class = [:item_class] first_item = [:first] || '<<' prev_item = [:prev] || '<' next_item = [:next] || '>' last_item = [:last] || '>>' content_tag :ul, class:pagination_class do content_tag(:li, link_to(first_item, '#', class: ([item_class] + ['first']).flatten.compact.join(' ')), class: item_wrapper_class)+ content_tag(:li, link_to(prev_item, '#', class: ([item_class] + ['prev'] ).flatten.compact.join(' ')), class: item_wrapper_class)+ content_tag(:li, content_tag(:span, nil, class: ([item_class] + [page_display_class]).flatten.compact.join(' ')), class: item_wrapper_class)+ content_tag(:li, link_to(next_item, '#', class: ([item_class] + ['next'] ).flatten.compact.join(' ')), class: item_wrapper_class)+ content_tag(:li, link_to(last_item, '#', class: ([item_class] + ['last'] ).flatten.compact.join(' ')), class: item_wrapper_class) end.html_safe end |