Skip to content

Commit b291b80

Browse files
author
John Durkin
committed
make nulls first/last an option
1 parent 2f1eb9e commit b291b80

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/ajax-datatables-rails/base.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def fetch_records
7575
def sort_records(records)
7676
sort_by = []
7777
params[:order].each_value do |item|
78-
sort_by << "#{sort_column(item)} #{sort_direction(item)}"
78+
sort_by << "#{sort_column(item)} #{sort_direction(item)} #{sort_nulls(item)}"
7979
end
8080
records.order(sort_by.join(", "))
8181
end
@@ -188,6 +188,11 @@ def sort_direction(item)
188188
options.include?(item[:dir]) ? item[:dir].upcase : 'ASC'
189189
end
190190

191+
def sort_nulls(item)
192+
options = %w(first last)
193+
options.include?(item[:nulls]) ? item[:nulls].upcase : 'LAST'
194+
end
195+
191196
def sortable_displayed_columns
192197
@sortable_displayed_columns ||= generate_sortable_displayed_columns
193198
end

0 commit comments

Comments
 (0)