This will return all the data that DataTables expects including all the relevant rows from the database.
# File app/datatables/request_logs_datatable.rb, line 6 def as_json(options = {}) conditions = if params[:sSearch].present? ["user_id is NOT NULL AND DATE_FORMAT(created_at,'%m/%d/%Y') like :search", search: "%#{params[:sSearch]}%"] else ["user_id is NOT NULL"] end as_datatable(RequestLog, conditions) end
This fetches the correct page of data in the correct order.
# File app/datatables/request_logs_datatable.rb, line 17 def data_hash(request_log) { id: request_log.id, name: request_log.user.try(:full_name), action: request_log.request_hash(request_log.controller, request_log.action), parameters: request_log.parameters.collect {|k,v| "#{k}=#{v}"}.join(', '), url: request_log.url, ip_address: request_log.ip_address, created_at: request_log.created_at.day_month_date_hr_min_mer } end
Provide the sequence in which columns to be sorted.
# File app/datatables/request_logs_datatable.rb, line 30 def sort_columns ['NULL','NULL','NULL','NULL','created_at'] end