Skip to content

Commit

Permalink
fix: default sort (#2760)
Browse files Browse the repository at this point in the history
* fix: default sort

* fix
  • Loading branch information
Paul-Bob authored May 9, 2024
1 parent 5e0dae2 commit f5625da
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/avo/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ def apply_sorting
@query = if field.present? && field.sortable.is_a?(Proc)
Avo::ExecutionContext.new(target: field.sortable, query: @query, direction: sanitized_sort_direction).handle
# Sanitize sort_by param by checking if have bounded field.
elsif field.present? && sanitized_sort_direction
elsif (field.present? || sort_by == :created_at) && sanitized_sort_direction
@query.order("#{@resource.model_class.table_name}.#{sort_by} #{sanitized_sort_direction}")
# Transform Model to ActiveRecord::Relation because Avo expects one.
else
Expand All @@ -612,7 +612,7 @@ def apply_sorting

# Sanitize sort_direction param
def sanitized_sort_direction
@sanitized_sort_direction ||= @index_params[:sort_direction].presence_in(["asc", "desc"])
@sanitized_sort_direction ||= @index_params[:sort_direction].presence_in(["asc", :asc, "desc", :desc])
end
end
end

0 comments on commit f5625da

Please sign in to comment.