class CustomersDatatable

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/customers_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(Customer, conditions)
end
data_hash(customer) click to toggle source

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

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

Provide the sequence in which columns to be sorted.

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