class SubjectsDatatable

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/subjects_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(Subject.includes(:courses), conditions)
end
data_hash(subject) click to toggle source

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

# File app/datatables/subjects_datatable.rb, line 16
def data_hash(subject)
  {
    id: subject.id,
    name: link_to(subject.name, admin_subject_courses_path(subject)),
    description: subject.description,
    sub_subjects: link_to(subject.courses_count, admin_subject_courses_path(subject)),
    action: admin_action_link(subject)
  }
end
sort_columns() click to toggle source

Provide the sequence in which columns to be sorted.

# File app/datatables/subjects_datatable.rb, line 27
def sort_columns
  ['name', 'description', 'courses_count']
end