Module: Effective::EffectiveDatatable::Dsl::Datatable
- Included in:
- DatatableDslTool
- Defined in:
- app/models/effective/effective_datatable/dsl/datatable.rb
Instance Method Summary collapse
- #actions_col(btn_class: nil, col_class: nil, inline: nil, partial: nil, partial_as: nil, actions_partial: nil, responsive: 5000, visible: true, **actions, &format) ⇒ Object
- #aggregate(name, label: nil, &compute) ⇒ Object
-
#bulk_actions_col(col_class: nil, input_name: nil, partial: nil, partial_as: nil, responsive: 5000) ⇒ Object
Called automatically after bulk_actions do …
-
#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
Instance Methods inside the datatable do ..
- #order(name, dir = nil) ⇒ Object
- #reorder(name, dir = nil) ⇒ Object
-
#reorder_col(name, col_class: nil, partial: nil, partial_as: nil, sql_column: nil, responsive: 5000) ⇒ Object
Called automatically after reorder Call again if you want to change the position of the reorder_col.
-
#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(btn_class: nil, col_class: nil, inline: nil, partial: nil, partial_as: nil, actions_partial: nil, responsive: 5000, visible: true, **actions, &format) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 85 def actions_col(btn_class: nil, col_class: nil, inline: nil, partial: nil, partial_as: nil, actions_partial: nil, responsive: 5000, visible: true, **actions, &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, btn_class: (btn_class || 'btn-sm btn-outline-primary'), col_class: col_class, format: (format if block_given?), index: nil, inline: (inline.nil? ? datatable.inline? : inline), label: false, name: :actions, partial: partial, partial_as: partial_as, actions_partial: (actions_partial || :dropleft), responsive: responsive, search: false, sort: false, sql_column: nil, th: nil, th_append: nil, visible: visible, # { approve: false }. These args are passed to effective_resources render_resource_actions actions: actions ) end |
#aggregate(name, label: nil, &compute) ⇒ Object
115 116 117 118 119 120 121 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 115 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, input_name: nil, partial: nil, partial_as: nil, responsive: 5000) ⇒ Object
Called automatically after bulk_actions do … end Call again if you want to change the position of the bulk_actions_col
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 125 def bulk_actions_col(col_class: nil, input_name: nil, partial: nil, partial_as: nil, responsive: 5000) datatable._columns.delete(:_bulk_actions) if datatable.columns[:_bulk_actions] datatable._columns[:_bulk_actions] = Effective::DatatableColumn.new( action: false, as: :bulk_actions, compute: nil, col_class: col_class, format: nil, index: nil, input_name: (input_name || 'bulk_actions_resources'), label: false, 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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 31 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, as: as, compute: nil, col_class: col_class, format: (format if block_given?), index: nil, label: (label.nil? ? name.to_s.split('.').last.titleize : label), 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
Instance Methods inside the datatable do .. end block
6 7 8 9 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 6 def length(length) raise 'length must be 5, 10, 25, 50, 100, 250, 500, :all' unless [5, 10, 25, 50, 100, 250, 500, :all].include?(length) datatable.state[:length] ||= (length == :all ? 9999999 : length) end |
#order(name, dir = nil) ⇒ Object
11 12 13 14 15 16 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 11 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 |
#reorder(name, dir = nil) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 18 def reorder(name, dir = nil) raise 'order direction must be :asc or :desc' unless [nil, :asc, :desc].include?(dir) datatable.state[:order_name] = :_reorder datatable.state[:order_dir] = dir reorder_col(name) end |
#reorder_col(name, col_class: nil, partial: nil, partial_as: nil, sql_column: nil, responsive: 5000) ⇒ Object
Called automatically after reorder Call again if you want to change the position of the reorder_col
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 152 def reorder_col(name, col_class: nil, partial: nil, partial_as: nil, sql_column: nil, responsive: 5000) datatable._columns.delete(:_reorder) if datatable.columns[:_reorder] datatable._columns[:_reorder] = Effective::DatatableColumn.new( action: false, as: :reorder, compute: nil, col_class: col_class, format: nil, index: nil, label: false, name: :reorder, partial: partial || '/effective/datatables/reorder_column', partial_as: partial_as, reorder: name, responsive: responsive, search: false, sort: true, sql_column: (sql_column || name), th: nil, th_append: nil, visible: false ) 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
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 59 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, as: as, compute: (compute if block_given?), col_class: col_class, format: nil, index: nil, label: (label.nil? ? name.to_s.split('.').last.titleize : label), 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 |