Module: Effective::EffectiveDatatable::Ajax
- Included in:
- Datatable
- Defined in:
- app/models/effective/effective_datatable/ajax.rb
Instance Method Summary collapse
- #display_entries ⇒ Object
-
#display_table_columns ⇒ Object
This is for the ColReorder plugin It sends us a list of columns that are different than our table_columns order So this method just returns an array of column names, as per ColReorder.
- #order_direction ⇒ Object
- #order_index ⇒ Object
- #order_name ⇒ Object
- #page ⇒ Object
- #per_page ⇒ Object
- #per_page=(length) ⇒ Object
-
#search_column(collection, table_column, search_term) ⇒ Object
This is here so classes that inherit from Datatables can can override the specific where clauses on a search column.
- #search_terms ⇒ Object
Instance Method Details
#display_entries ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/models/effective/effective_datatable/ajax.rb', line 44 def display_entries @display_entries ||= begin entries = (@default_entries.presence || EffectiveDatatables.default_entries) entries = -1 if entries.to_s.downcase == 'all' [10, 25, 50, 100, 250, 1000, -1].include?(entries) ? entries : 25 end end |
#display_table_columns ⇒ Object
This is for the ColReorder plugin It sends us a list of columns that are different than our table_columns order So this method just returns an array of column names, as per ColReorder
10 11 12 13 14 15 16 17 |
# File 'app/models/effective/effective_datatable/ajax.rb', line 10 def display_table_columns return nil if params[:columns].blank? @display_table_columns ||= params[:columns].each_with_object({}) do |(_, column), retval| retval[column[:name]] = table_columns[column[:name]] # Same order as ColReordernow retval[column[:name]][:visible] = (column[:visible] == 'true') # As per ColVis end end |
#order_direction ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'app/models/effective/effective_datatable/ajax.rb', line 34 def order_direction @order_direction ||= if params[:order].present? params[:order].first[1][:dir] == 'desc' ? 'DESC' : 'ASC' elsif @default_order.present? @default_order.values.first.to_s.downcase == 'desc' ? 'DESC' : 'ASC' else 'ASC' end end |
#order_index ⇒ Object
30 31 32 |
# File 'app/models/effective/effective_datatable/ajax.rb', line 30 def order_index (table_columns[order_name][:index] || 0) rescue 0 end |
#order_name ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/effective/effective_datatable/ajax.rb', line 19 def order_name @order_name ||= begin if params[:order] && params[:columns] order_column_index = (params[:order].first[1][:column] rescue '0') (params[:columns][order_column_index] || {})[:name] elsif @default_order.present? @default_order.keys.first end || table_columns.keys.first end end |
#page ⇒ Object
100 101 102 |
# File 'app/models/effective/effective_datatable/ajax.rb', line 100 def page params[:start].to_i / per_page + 1 end |
#per_page ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/effective/effective_datatable/ajax.rb', line 77 def per_page return 9999999 if simple? length = (params[:length].presence || display_entries).to_i if length == -1 9999999 elsif length > 0 length else 25 end end |
#per_page=(length) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'app/models/effective/effective_datatable/ajax.rb', line 91 def per_page=(length) case length when Integer params[:length] = length when :all params[:length] = -1 end end |
#search_column(collection, table_column, search_term) ⇒ Object
This is here so classes that inherit from Datatables can can override the specific where clauses on a search column
69 70 71 72 73 74 75 |
# File 'app/models/effective/effective_datatable/ajax.rb', line 69 def search_column(collection, table_column, search_term) if table_column[:array_column] array_tool.search_column_with_defaults(collection, table_column, search_term) else table_tool.search_column_with_defaults(collection, table_column, search_term) end end |
#search_terms ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/effective/effective_datatable/ajax.rb', line 52 def search_terms @search_terms ||= HashWithIndifferentAccess.new().tap do |terms| if params[:columns].present? # This is an AJAX request from the DataTable (params[:columns] || {}).each do |_, column| next if table_columns[column[:name]].blank? || (column[:search] || {})[:value].blank? terms[column[:name]] = column[:search][:value] end else # This is the initial render, and we have to apply default search terms only table_columns.each do |name, values| terms[name] = values[:filter][:selected] if values[:filter][:selected].present? end end end end |