diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 147d17a2..c084aea1 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -139,12 +139,25 @@ def per_page end def sort_column(item) - sortable_columns[item['column'].to_i] + sortable_columns[sortable_displayed_columns.index(item[:column])] end def sort_direction(item) options = %w(desc asc) options.include?(item['dir']) ? item['dir'].upcase : 'ASC' end + + def sortable_displayed_columns + @sortable_displayed_columns ||= generate_sortable_displayed_columns + end + + def generate_sortable_displayed_columns + @sortable_displayed_columns = [] + params[:columns].each_value do |column| + @sortable_displayed_columns << column[:data] if column[:orderable] == 'true' + end + @sortable_displayed_columns + end + end end