Module: TrkDatatables::BaseHelpers
- Included in:
- Base
- Defined in:
- lib/trk_datatables/base_helpers.rb
Instance Method Summary collapse
-
#form_field_name(column_key) ⇒ Object
Get the form field name for column.
-
#order_set(column_key, direction = :asc, view = nil) ⇒ Object
Set sort for column.
-
#param_set(column_key, value, view = nil) ⇒ Object
Set params for column search.
-
#range_string(range) ⇒ Object
For range you can this helper to insert BETWEEN_SEPARATOR.
Instance Method Details
#form_field_name(column_key) ⇒ Object
Get the form field name for column. This is class method so you do not need datatable instance. It returns something like ‘column[search]`. For global search you can use ’[search]‘
form_tag url: posts_path, method: :get do |f|
f.text_field PostsDatatable.form_field_name('users.email'), '[email protected]'
# it is the same as
f.text_field 'columns[3][search][value]', '[email protected]'
46 47 48 49 50 |
# File 'lib/trk_datatables/base_helpers.rb', line 46 def form_field_name(column_key) datatable = new OpenStruct.new(params: {}) column_index = datatable.index_by_column_key column_key DtParams.form_field_name column_index end |
#order_set(column_key, direction = :asc, view = nil) ⇒ Object
Set sort for column. This is class method so you do not need datatable instance.
30 31 32 33 34 |
# File 'lib/trk_datatables/base_helpers.rb', line 30 def order_set(column_key, direction = :asc, view = nil) datatable = new view || OpenStruct.new(params: {}) column_index = datatable.index_by_column_key column_key DtParams.order_set column_index, direction end |
#param_set(column_key, value, view = nil) ⇒ Object
Set params for column search. This is class method so you do not need datatable instance.
You can always use your params for filtering outside of datatable and merge to params
16 17 18 19 20 21 22 |
# File 'lib/trk_datatables/base_helpers.rb', line 16 def param_set(column_key, value, view = nil) datatable = new view || OpenStruct.new(params: {}) value = value.join MULTIPLE_OPTION_SEPARATOR if value.is_a? Array value = [value.first, value.last].join BETWEEN_SEPARATOR if value.is_a? Range column_index = datatable.index_by_column_key column_key DtParams.param_set column_index, value end |
#range_string(range) ⇒ Object
For range you can this helper to insert BETWEEN_SEPARATOR
53 54 55 56 57 58 59 |
# File 'lib/trk_datatables/base_helpers.rb', line 53 def range_string(range) raise Error, "#{range} is not a Range" unless range.is_a? Range from = range.min to = range.max "#{from} #{BETWEEN_SEPARATOR} #{to}" end |