class UserActivitiesDatatable

Public Instance Methods

as_json(options = {}) click to toggle source

This will return all the data that DataTables expects including all the relevant rows from the database.

# File app/datatables/user_activities_datatable.rb, line 6
def as_json(options = {})
  conditions = if params[:sSearch].present?
    ["LOWER(name) LIKE :q", q: "%#{params[:sSearch].downcase}%"]
  else
    {}
  end
  as_datatable(User.joins(:request_logs).where.not("user_id is NULL").uniq, conditions)
end
data_hash(user) click to toggle source

This fetches the correct page of data in the correct order.

# File app/datatables/user_activities_datatable.rb, line 16
def data_hash(user)
  {
    id: user.id,
    name: user.try(:full_name),
    user_activity_link: user_activity_link(user.id),
    created_at: user.request_logs.last.created_at.day_month_date_hr_min_mer
  }
end
sort_columns() click to toggle source

Provide the sequence in which columns to be sorted.

# File app/datatables/user_activities_datatable.rb, line 26
def sort_columns
  ['NULL', 'NULL', 'created_at']
end