mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-26 00:36:01 +08:00
Fix sorting by status in team members table [SCI-4179]
This commit is contained in:
parent
ee73088a81
commit
0e545dfee0
1 changed files with 23 additions and 1 deletions
|
@ -18,7 +18,7 @@ class TeamUsersDatatable < CustomDatatable
|
|||
'User.email',
|
||||
'UserTeam.role',
|
||||
'UserTeam.created_at',
|
||||
'User.confirmed_at',
|
||||
'User.status'
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -82,6 +82,16 @@ class TeamUsersDatatable < CustomDatatable
|
|||
end
|
||||
end
|
||||
|
||||
# Overwrite default pagination method as here
|
||||
# we need to be able work also with arrays
|
||||
def paginate_records(records)
|
||||
records.to_a.drop(offset).first(per_page)
|
||||
end
|
||||
|
||||
def load_paginator
|
||||
self
|
||||
end
|
||||
|
||||
# Query database for records (this will be later paginated and filtered)
|
||||
# after that "data" function will return json
|
||||
def get_raw_records
|
||||
|
@ -91,4 +101,16 @@ class TeamUsersDatatable < CustomDatatable
|
|||
.where(team: @team)
|
||||
.distinct
|
||||
end
|
||||
|
||||
def sort_records(records)
|
||||
if sort_column(order_params) == 'users.status'
|
||||
records = records.sort_by { |record| record.user.active_status_str }
|
||||
order_params['dir'] == 'asc' ? records : records.reverse
|
||||
elsif sort_column(order_params) == 'user_teams.role'
|
||||
records = records.sort_by(&:role_str)
|
||||
order_params['dir'] == 'asc' ? records : records.reverse
|
||||
else
|
||||
super(records)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue