class UniversitiesDatatable

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

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

# File app/datatables/universities_datatable.rb, line 17
def data_hash(university)
  {
    id: university.id,
    name: link_to(university.name, admin_path(university_id: university.subdomain), target: :_blank),
    subdomain: university.subdomain,
    active: admin_university_activation_link(university)
  }
end
sort_columns() click to toggle source

Provide the sequence in which columns to be sorted.

# File app/datatables/universities_datatable.rb, line 27
def sort_columns
  %w(name subdomain active)
end