Merge pull request #7852 from aignatov-bio/ai-sci-11047-add-sorting-to-list-of-locations

Add sorting to list of locations [SCI-11047]
This commit is contained in:
aignatov-bio 2024-09-16 10:07:56 +02:00 committed by GitHub
commit 53c6056706
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View file

@ -132,7 +132,7 @@ export default {
{
field: 'reminders',
headerName: this.i18n.t('storage_locations.show.table.reminders'),
sortable: true,
sortable: false,
cellRenderer: RemindersRender
},
{
@ -149,7 +149,7 @@ export default {
{
field: 'stock',
headerName: this.i18n.t('storage_locations.show.table.stock'),
sortable: true
sortable: false
}];
return columns;

View file

@ -13,5 +13,26 @@ module Lists
end
def filter_records; end
def sort_records
return unless @params[:order]
sort = "#{order_params[:column]}_#{sort_direction(order_params)}"
case sort
when 'position_formatted_ASC'
@records = @records.order(Arel.sql("metadata -> 'position' -> 0 ASC, metadata -> 'position' -> 1 ASC"))
when 'position_formatted_DESC'
@records = @records.order(Arel.sql("metadata -> 'position' -> 0 DESC, metadata -> 'position' -> 1 DESC"))
when 'row_id_ASC'
@records = @records.order(repository_row_id: :asc)
when 'row_id_DESC'
@records = @records.order(repository_row_id: :desc)
when 'row_name_ASC'
@records = @records.joins(:repository_row).order('repository_rows.name ASC')
when 'row_name_DESC'
@records = @records.joins(:repository_row).order('repository_rows.name DESC')
end
end
end
end