Module: Dbviewer::DatatableSupport
- Extended by:
- ActiveSupport::Concern
- Included in:
- DatabaseOperations
- Defined in:
- app/controllers/concerns/dbviewer/datatable_support.rb
Instance Method Summary collapse
-
#fetch_datatable_data(table_name, query_params) ⇒ Object
Consolidated method to fetch all datatable-related data in one call Returns a hash containing all necessary datatable information.
Instance Method Details
#fetch_datatable_data(table_name, query_params) ⇒ Object
Consolidated method to fetch all datatable-related data in one call Returns a hash containing all necessary datatable information
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/concerns/dbviewer/datatable_support.rb', line 7 def fetch_datatable_data(table_name, query_params) columns = fetch_table_columns(table_name) return default_datatable_structure(table_name) if columns.empty? if query_params.column_filters.empty? total_count = fetch_table_record_count(table_name) else total_count = fetch_filtered_record_count(table_name, query_params.column_filters) end { columns: columns, records: fetch_table_records(table_name, query_params), total_count: total_count, total_pages: total_count > 0 ? (total_count.to_f / query_params.per_page).ceil : 0, metadata: (table_name), current_page: query_params.page, per_page: query_params.per_page, order_by: query_params.order_by, direction: query_params.direction } end |