Skip to content

Commit 9b9be04

Browse files
committed
Allow disabling of columns orderable to play nice with sortable_columns
1 parent f7744b6 commit 9b9be04

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/ajax-datatables-rails/base.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,25 @@ def per_page
139139
end
140140

141141
def sort_column(item)
142-
sortable_columns[item['column'].to_i]
142+
sortable_columns[sortable_diplayed_columns.index(item[:column])]
143143
end
144144

145145
def sort_direction(item)
146146
options = %w(desc asc)
147147
options.include?(item['dir']) ? item['dir'].upcase : 'ASC'
148148
end
149+
150+
def sortable_diplayed_columns
151+
@sortable_diplayed_columns ||= generate_sortable_diplayed_columns
152+
end
153+
154+
def generate_sortable_diplayed_columns
155+
@sortable_diplayed_columns = []
156+
params[:columns].each_value do |column|
157+
@sortable_diplayed_columns << column[:data] if column[:orderable] == 'true'
158+
end
159+
@sortable_diplayed_columns
160+
end
161+
149162
end
150163
end

0 commit comments

Comments
 (0)