This will return all the data that DataTables expects including all the relevant rows from the database.
# File app/datatables/testimonials_datatable.rb, line 6 def as_json(options = {}) conditions = if params[:sSearch].present? ["LOWER(name) LIKE :q", q: "%#{params[:sSearch].downcase}%"] else {} end as_datatable(Testimonial, conditions) end
This fetches the correct page of data in the correct order.
# File app/datatables/testimonials_datatable.rb, line 16 def data_hash(testimonial) { id: testimonial.id, heading: testimonial.heading, name: (link_to testimonial.name, admin_testimonial_path(testimonial), data: {toggle: 'modal', target: '#remote-modal'}), position: testimonial.position, university_name: testimonial.university_name, active: admin_testimonial_activation_link(testimonial), action: admin_action_link(testimonial), description: testimonial.description } end
Provide the sequence in which columns to be sorted.
# File app/datatables/testimonials_datatable.rb, line 30 def sort_columns ['name', 'heading', 'university_name', 'position'] end