class CategoriesDatatable

Public Instance Methods

as_json(options = {}) click to toggle source

The #as_json method is triggered behind the scenes by the render_json call in the controller. This will return all the data that DataTables expects including all the relevant rows from the database.

# File app/datatables/categories_datatable.rb, line 5
def as_json(options = {})
  conditions = if params[:sSearch].present?
    ["LOWER(name) LIKE :q", q: "%#{params[:sSearch].downcase}%"]
  else
    {}
  end
  as_datatable(Category, conditions)
end
data_hash(category) click to toggle source

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

# File app/datatables/categories_datatable.rb, line 15
def data_hash(category)
  {
    id: category.id,
    name: category.name,
    display_on_homepage: admin_category_display_on_homepage_link(category),
    no_of_tutors: 0,#category.tutors.size,
    action: admin_action_link(category)
  }
end
sort_columns() click to toggle source

Provide the sequence in which columns to be sorted.

# File app/datatables/categories_datatable.rb, line 26
def sort_columns
  ['name', nil, 'display_on_homepage']
end