Module: FlexibleDatatables::ActiveRecordSorter
- Defined in:
- lib/flexible_datatables/sorters/active_record_sorter.rb
Class Method Summary collapse
Class Method Details
.sort(opts = {}) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/flexible_datatables/sorters/active_record_sorter.rb', line 3 def self.sort(opts = {}) columns = opts.fetch(:columns) records = opts.fetch(:records, []) order_opts = opts.fetch(:order) sort_col = columns[order_opts['0'].fetch(:column).to_i] sort_dir = order_opts['0'].fetch(:dir) == 'desc' ? 'desc' : 'asc' records.order("#{sort_col} #{sort_dir}") end |