Module: Effective::EffectiveDatatable::Dsl::Datatable
- Included in:
- DatatableDslTool
- Defined in:
- app/models/effective/effective_datatable/dsl/datatable.rb
Instance Method Summary collapse
- #actions_col(show: true, edit: true, destroy: true, col_class: nil, partial: nil, partial_as: nil, responsive: 5000, visible: true, &format) ⇒ Object
- #aggregate(name, label: nil, &compute) ⇒ Object
- #bulk_actions_col(col_class: nil, partial: nil, partial_as: nil, responsive: 5000) ⇒ Object
-
#col(name, action: nil, as: nil, col_class: nil, label: nil, partial: nil, partial_as: nil, responsive: 10000, search: {}, sort: true, sql_column: nil, th: nil, th_append: nil, visible: true, &format) ⇒ Object
A col has its internal values sorted/searched before the block is run Anything done in the block, is purely a format on the after sorted/ordered value the original object == the computed value, which is yielded to the format block You can’t do compute with .col.
- #length(length) ⇒ Object
-
#order(name, dir = nil) ⇒ Object
Instance Methods inside the datatable do ..
-
#val(name, action: nil, as: nil, col_class: nil, label: nil, partial: nil, partial_as: nil, responsive: 10000, search: {}, sort: true, sql_column: false, th: nil, th_append: nil, visible: true, &compute) ⇒ Object
A val is a computed value that is then sorted/searched after the block is run You can have another block by calling .format afterwards to work on the computed value itself.
Instance Method Details
#actions_col(show: true, edit: true, destroy: true, col_class: nil, partial: nil, partial_as: nil, responsive: 5000, visible: true, &format) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 100 def actions_col(show: true, edit: true, destroy: true, col_class: nil, partial: nil, partial_as: nil, responsive: 5000, visible: true, &format) raise 'You can only have one actions column' if datatable.columns[:_actions].present? datatable._columns[:_actions] = Effective::DatatableColumn.new( action: false, as: :actions, compute: nil, col_class: col_class, format: (format if block_given?), index: datatable.columns.length, label: '', name: :actions, partial: partial || '/effective/datatables/actions_column', partial_as: partial_as, responsive: responsive, search: false, sort: false, sql_column: nil, th: nil, th_append: nil, visible: visible, show: show, edit: edit, destroy: destroy ) end |
#aggregate(name, label: nil, &compute) ⇒ Object
128 129 130 131 132 133 134 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 128 def aggregate(name, label: nil, &compute) datatable._aggregates[name.to_sym] = { compute: (compute if block_given?), label: label || name.to_s.titleize, name: name.to_sym, } end |
#bulk_actions_col(col_class: nil, partial: nil, partial_as: nil, responsive: 5000) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 76 def bulk_actions_col(col_class: nil, partial: nil, partial_as: nil, responsive: 5000) raise 'You can only have one bulk actions column' if datatable.columns[:_bulk_actions].present? datatable._columns[:_bulk_actions] = Effective::DatatableColumn.new( action: false, as: :bulk_actions, compute: nil, col_class: col_class, format: nil, index: datatable.columns.length, label: '', name: :bulk_actions, partial: partial || '/effective/datatables/bulk_actions_column', partial_as: partial_as, responsive: responsive, search: { as: :bulk_actions }, sort: false, sql_column: nil, th: nil, th_append: nil, visible: true, ) end |
#col(name, action: nil, as: nil, col_class: nil, label: nil, partial: nil, partial_as: nil, responsive: 10000, search: {}, sort: true, sql_column: nil, th: nil, th_append: nil, visible: true, &format) ⇒ Object
A col has its internal values sorted/searched before the block is run Anything done in the block, is purely a format on the after sorted/ordered value the original object == the computed value, which is yielded to the format block You can’t do compute with .col
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 22 def col(name, action: nil, as: nil, col_class: nil, label: nil, partial: nil, partial_as: nil, responsive: 10000, search: {}, sort: true, sql_column: nil, th: nil, th_append: nil, visible: true, &format) raise 'You cannot use partial: ... with the block syntax' if partial && block_given? name = name.to_sym unless name.to_s.include?('.') datatable._columns[name] = Effective::DatatableColumn.new( action: action, # resource columns only as: as, compute: nil, col_class: col_class, format: (format if block_given?), index: datatable.columns.length, label: label || name.to_s.split('.').last.titleize, name: name, partial: partial, partial_as: partial_as, responsive: responsive, search: search, sort: sort, sql_column: sql_column, th: th, th_append: th_append, visible: visible, ) end |
#length(length) ⇒ Object
13 14 15 16 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 13 def length(length) raise 'length must be 10, 25, 50, 100, 250, 1000, :all' unless [10, 25, 50, 100, 250, 1000, :all].include?(length) datatable.state[:length] ||= (length == :all ? 9999999 : length) end |
#order(name, dir = nil) ⇒ Object
Instance Methods inside the datatable do .. end block
6 7 8 9 10 11 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 6 def order(name, dir = nil) raise 'order direction must be :asc or :desc' unless [nil, :asc, :desc].include?(dir) datatable.state[:order_name] ||= name datatable.state[:order_dir] ||= dir end |
#val(name, action: nil, as: nil, col_class: nil, label: nil, partial: nil, partial_as: nil, responsive: 10000, search: {}, sort: true, sql_column: false, th: nil, th_append: nil, visible: true, &compute) ⇒ Object
A val is a computed value that is then sorted/searched after the block is run You can have another block by calling .format afterwards to work on the computed value itself
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 50 def val(name, action: nil, as: nil, col_class: nil, label: nil, partial: nil, partial_as: nil, responsive: 10000, search: {}, sort: true, sql_column: false, th: nil, th_append: nil, visible: true, &compute) raise 'You cannot use partial: ... with the block syntax' if partial && block_given? name = name.to_sym unless name.to_s.include?('.') datatable._columns[name] = Effective::DatatableColumn.new( action: action, # Resource columns only as: as, compute: (compute if block_given?), col_class: col_class, format: nil, index: datatable.columns.length, label: label || name.to_s.split('.').last.titleize, name: name, partial: partial, partial_as: partial_as, responsive: responsive, search: search, sort: sort, sql_column: (block_given? ? false : sql_column), th: th, th_append: th_append, visible: visible, ) end |