Module: DatatableHelper
- Defined in:
- app/helpers/datatable_helper.rb
Overview
Helper methods for rendering JQuery Datatables
Instance Method Summary collapse
- #datatable_columns(object, cols) ⇒ Object
- #default_datatable_columns(object) ⇒ Object
- #render_datatable(object, table_url, columns: nil, table_name: nil, aoData: [], initial_size: 25, table_views: { table: true, grid: false }, table_filters: [], table_actions: nil, sort: [[0, 'asc']]) ⇒ Object
Instance Method Details
#datatable_columns(object, cols) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/datatable_helper.rb', line 9 def datatable_columns(object, cols) obj_name = object.to_s.underscore.pluralize cols.map do |col| if col == 'actions' { title: '', data: "#{obj_name.tr('/', '_')}__actions", class: 'actions center', bSortable: false } else { title: col.split('_').collect(&:capitalize).join(' ').to_s, data: "#{obj_name}__#{col}", visible: true } end end end |
#default_datatable_columns(object) ⇒ Object
5 6 7 |
# File 'app/helpers/datatable_helper.rb', line 5 def default_datatable_columns(object) datatable_columns(object, ['actions'] + object.column_names) end |
#render_datatable(object, table_url, columns: nil, table_name: nil, aoData: [], initial_size: 25, table_views: { table: true, grid: false }, table_filters: [], table_actions: nil, sort: [[0, 'asc']]) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/helpers/datatable_helper.rb', line 22 def render_datatable(object, table_url, columns: nil, table_name: nil, aoData: [], initial_size: 25, table_views: { table: true, grid: false }, table_filters: [], table_actions: nil, sort: [[0, 'asc']]) warn("DEPRECATION WARNING: render_datatable will be removed soon (use render partial: 'partials/table' instead)") if table_name.nil? table_name = object.to_s.pluralize.underscore.tr('/', '_') end columns = default_datatable_columns(object) if columns.nil? render( partial: 'partials/table', locals: { table_name: table_name, aoData: aoData, columns: columns, sort: sort, table_filters: table_filters, table_views: table_views, initial_size: initial_size, table_actions: table_actions, table_url: table_url }.merge(request.query_parameters), formats: [:html] ) end |