This will return all the data that DataTables expects including all the relevant rows from the database.
# File app/datatables/tutors_datatable.rb, line 13 def as_json(options = {}) conditions = if params[:sSearch].present? ["LOWER(name) LIKE :q", q: "%#{params[:sSearch].downcase}%"] else {} end tutors = params[:nonsearchable_only].present? ? Tutor.non_searchable : Tutor.all as_datatable(tutors, conditions) end
This fetches the correct page of data in the correct order.
# File app/datatables/tutors_datatable.rb, line 25 def data_hash(tutor) { id: tutor.id, name: tutor.full_name, email: mail_to(tutor.email), is_registration_completed: admin_tutor_status_link(tutor), active: admin_user_activation_link(tutor), searchable: admin_tutor_searchable_link(tutor), admin: admin_user_admin_link(tutor), is_featured: admin_tutor_featured_link(tutor), upload_image: admin_user_image_upload_form(tutor), user_activity: user_activity_link(tutor) } end
Provide the sequence in which columns to be sorted.
# File app/datatables/tutors_datatable.rb, line 41 def sort_columns %w(name email is_registration_completed activation_state searchable admin) end