class StudentsDatatable

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/students_datatable.rb, line 11
def as_json(options = {})
  conditions = if params[:sSearch].present?
    ["LOWER(name) LIKE :q", q: "%#{params[:sSearch].downcase}%"]
  else
    {}
  end
  as_datatable(Student, conditions)
end
data_hash(student) click to toggle source

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

# File app/datatables/students_datatable.rb, line 21
def data_hash(student)
  {
    id: student.id,
    name: student.full_name,
    email: mail_to(student.email),
    is_registration_completed: admin_student_status_link(student),
    searchable: admin_student_searchable_link(student),
    active: admin_user_activation_link(student),
    admin: admin_user_admin_link(student),
    upload_image: admin_user_image_upload_form(student),
    user_activity: user_activity_link(student)
  }
end
sort_columns() click to toggle source

Provide the sequence in which columns to be sorted.

# File app/datatables/students_datatable.rb, line 36
def sort_columns
  %w(name email is_registration_completed activation_state searchable admin)
end