class CompaniesDatatable

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/companies_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(Company, conditions)
end
data_hash(company) click to toggle source

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

# File app/datatables/companies_datatable.rb, line 17
def data_hash(company)
  {
    id: company.id,
    name: link_to(company.name, admin_path(company_id: company.subdomain), target: :_blank),
    subdomain: company.subdomain,
    active: admin_company_activation_link(company)
  }
end
sort_columns() click to toggle source

Provide the sequence in which columns to be sorted.

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