Class: AjaxDatatablesRails::Base
- Inherits:
-
Object
- Object
- AjaxDatatablesRails::Base
- Defined in:
- lib/ajax-datatables-rails/base.rb
Direct Known Subclasses
Constant Summary collapse
- GLOBAL_SEARCH_DELIMITER =
' '
Instance Attribute Summary collapse
-
#datatable ⇒ Object
readonly
Returns the value of attribute datatable.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
-
#additional_data ⇒ Object
User overides.
-
#as_json ⇒ Object
JSON structure sent to jQuery DataTables.
- #column_data(column) ⇒ Object
-
#column_id(name) ⇒ Object
User helper methods.
- #data ⇒ Object
-
#fetch_records ⇒ Object
ORM defined methods.
- #filter_records(records) ⇒ Object
- #get_raw_records ⇒ Object
-
#initialize(params, options = {}) ⇒ Base
constructor
A new instance of Base.
- #paginate_records(records) ⇒ Object
- #sort_records(records) ⇒ Object
-
#view_columns ⇒ Object
User defined methods.
Constructor Details
Instance Attribute Details
#datatable ⇒ Object (readonly)
Returns the value of attribute datatable.
29 30 31 |
# File 'lib/ajax-datatables-rails/base.rb', line 29 def datatable @datatable end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
29 30 31 |
# File 'lib/ajax-datatables-rails/base.rb', line 29 def @options end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
29 30 31 |
# File 'lib/ajax-datatables-rails/base.rb', line 29 def params @params end |
Class Method Details
.default_db_adapter ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/ajax-datatables-rails/base.rb', line 15 def default_db_adapter if rails_52? ::ActiveRecord::Base.configurations.dig(Rails.env, 'adapter').downcase.to_sym elsif rails_60? ::ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).first.config['adapter'].downcase.to_sym else ::ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).first.adapter.downcase.to_sym end end |
Instance Method Details
#additional_data ⇒ Object
User overides
70 71 72 |
# File 'lib/ajax-datatables-rails/base.rb', line 70 def additional_data {} end |
#as_json ⇒ Object
JSON structure sent to jQuery DataTables
75 76 77 78 79 80 81 |
# File 'lib/ajax-datatables-rails/base.rb', line 75 def as_json(*) { recordsTotal: records_total_count, recordsFiltered: records_filtered_count, data: sanitize_data(data), }.merge(draw_id).merge(additional_data) end |
#column_data(column) ⇒ Object
88 89 90 91 |
# File 'lib/ajax-datatables-rails/base.rb', line 88 def column_data(column) id = column_id(column) params.dig('columns', id.to_s, 'search', 'value') end |
#column_id(name) ⇒ Object
User helper methods
84 85 86 |
# File 'lib/ajax-datatables-rails/base.rb', line 84 def column_id(name) view_columns.keys.index(name.to_sym) end |
#data ⇒ Object
48 49 50 |
# File 'lib/ajax-datatables-rails/base.rb', line 48 def data raise(NotImplementedError, data_error_text) end |
#fetch_records ⇒ Object
ORM defined methods
53 54 55 |
# File 'lib/ajax-datatables-rails/base.rb', line 53 def fetch_records get_raw_records end |
#filter_records(records) ⇒ Object
57 58 59 |
# File 'lib/ajax-datatables-rails/base.rb', line 57 def filter_records(records) raise(NotImplementedError) end |
#get_raw_records ⇒ Object
44 45 46 |
# File 'lib/ajax-datatables-rails/base.rb', line 44 def get_raw_records raise(NotImplementedError, raw_records_error_text) end |
#paginate_records(records) ⇒ Object
65 66 67 |
# File 'lib/ajax-datatables-rails/base.rb', line 65 def paginate_records(records) raise(NotImplementedError) end |
#sort_records(records) ⇒ Object
61 62 63 |
# File 'lib/ajax-datatables-rails/base.rb', line 61 def sort_records(records) raise(NotImplementedError) end |
#view_columns ⇒ Object
User defined methods
40 41 42 |
# File 'lib/ajax-datatables-rails/base.rb', line 40 def view_columns raise(NotImplementedError, view_columns_error_text) end |