mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-14 19:37:51 +08:00
fixes sorting of assigned column [fixes SCI-1483]
This commit is contained in:
parent
9eba178dce
commit
506e47a595
1 changed files with 18 additions and 4 deletions
|
@ -248,10 +248,7 @@ class RepositoryDatatable < AjaxDatatablesRails::Base
|
||||||
my_module_repository_rows.id IS NULL))"
|
my_module_repository_rows.id IS NULL))"
|
||||||
).order("my_module_repository_rows.id NULLS #{direction}")
|
).order("my_module_repository_rows.id NULLS #{direction}")
|
||||||
else
|
else
|
||||||
records.joins(
|
sort_assigned_records(records, params[:order].values[0]['dir'])
|
||||||
'LEFT OUTER JOIN my_module_repository_rows ON
|
|
||||||
(repository_rows.id = my_module_repository_rows.repository_row_id)'
|
|
||||||
).order("my_module_repository_rows.id NULLS #{direction}")
|
|
||||||
end
|
end
|
||||||
elsif sorting_by_custom_column
|
elsif sorting_by_custom_column
|
||||||
# Check if have to filter records first
|
# Check if have to filter records first
|
||||||
|
@ -391,4 +388,21 @@ class RepositoryDatatable < AjaxDatatablesRails::Base
|
||||||
|
|
||||||
@sortable_displayed_columns = sort_order
|
@sortable_displayed_columns = sort_order
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sort_assigned_records(records, direction)
|
||||||
|
assigned = records.joins(:my_module_repository_rows).distinct.pluck(:id)
|
||||||
|
unassigned = records.where.not(id: assigned).pluck(:id)
|
||||||
|
if direction == 'asc'
|
||||||
|
ids = assigned + unassigned
|
||||||
|
elsif direction == 'desc'
|
||||||
|
ids = unassigned + assigned
|
||||||
|
end
|
||||||
|
|
||||||
|
order_by_index = ActiveRecord::Base.send(
|
||||||
|
:sanitize_sql_array,
|
||||||
|
["position((',' || repository_rows.id || ',') in ?)",
|
||||||
|
ids.join(',') + ',']
|
||||||
|
)
|
||||||
|
records.order(order_by_index)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue