Module: StimulusRailsDatatables::DatatableHelper
- Defined in:
- app/helpers/stimulus_rails_datatables/datatable_helper.rb
Defined Under Namespace
Classes: DatatableBuilder
Instance Method Summary collapse
Instance Method Details
#datatable_for(id, source:, order: [[2, 'desc']], **options) {|DatatableBuilder.new(columns)| ... } ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/stimulus_rails_datatables/datatable_helper.rb', line 5 def datatable_for(id, source:, order: [[2, 'desc']], **) classes = .fetch(:classes, 'align-middle table w-100') searching = .fetch(:searching, true) length_change = .fetch(:length_change, true) columns = [] yield DatatableBuilder.new(columns) data = { controller: 'datatable', datatable_id_value: id, datatable_source_value: source, datatable_order_value: order.to_json, datatable_columns_value: columns.to_json, datatable_searching_value: searching, datatable_length_change_value: length_change } content_tag(:div, data: data) do content_tag(:table, class: classes, id: id) do content_tag(:thead, class: 'table-light align-middle') do content_tag(:tr) do safe_join(columns.map do |col| content_tag(:th, col[:title] || col[:data].to_s.titleize, class: col[:class]) end) end end end end end |