Closed zaracato closed 9 years ago
By the way, I try with WillPaginate with the same results. tks
Can you share your datatable class code?
yes, off course
class CategoryDatatable < AjaxDatatablesRails::Base AjaxDatatablesRails::Extensions::Kaminari def sortable_columns
@sortable_columns ||= ['categories.name']
end
def searchable_columns
@searchable_columns ||= ['categories.name']
end
private
def data records.map do |record| [
# example: record.attribute,
record.name
]
end
end
def get_raw_records
Category.all
end
end
Could you please replace the kaminari
extension inside the datatable class and use the simple_paginator
extension, like this?
class CategoryDatatable < AjaxDatatablesRails::Base
# replace this:
# AjaxDatatablesRails::Extensions::Kaminari
# with this:
AjaxDatatablesRails::Extensions::SimplePaginator
end
this will bypass using kaminari
at all, and send all pagination related methods straight to ActiveRecord
.
PS. Please, always format code in comments :smile: , that way it's easier for someone trying to help to read your code.
there is something that i dont understand (maybe cause Im a noob), this is the get that the datatable make http://localhost:3000/categories.json?sEcho=3&iColumns=1&sColumns=&iDisplayStart=30&iDisplayLength=10&mDataProp_0=0&sSearch_0=&bRegex_0=false&bSearchable_0=true&bSortable_0=true&sSearch=&bRegex=false&iSortCol_0=0&sSortDir_0=asc&iSortingCols=1&_=1426823449762
But In your code I see params[:start], params[:lenght] to get the json, but I didn find where the param change the name to 'iDisplayLength' for example, maybe that is the problem (Im testing with a fork of your gem)
I actually try with SimplePaginator with the same results , and tks , sorry for the format :P
:) Ok, that is an indication that you're using an old version of the jQuery.dataTables
plugin.
You need to use jQuery.dataTables
version 1.10 if you're using this gem's version 0.3.0 as stated in the README
fort this gem: https://github.com/antillas21/ajax-datatables-rails#versions
AAAAA, it works!! actually I have the 1.10.4 v of datatables but in my gemfile I had a wrong version of your gem, I put gem 'ajax-datatables-rails', '0.1.2' and it works!!, gracias paisa!
:) de nada, paisano.
I would like to make an update on this same issue. For me, my queries with this gem are always appended with LIMIT 10 OFFSET 0 when serverSide: false.
With serverSide: true it works as expected.
This is with Kaminari, ajax-datatables-rails (= 0.3.1) and jquery-datatables-rails (~> 3.3.0)
This problem occurs with all three paginator types.
That is very weird @Exanimous , kaminari
or will_paginate
modules may behave as you mention, but the SimplePaginator
module should just work as it goes straight to the database through the default ORM (activerecord).
Can you share code for your datatables class?
Sure thing, here is the code the the current datatable that is proving troublesome.
class SubjectDatatable < AjaxDatatablesRails::Base
include AjaxDatatablesRails::Extensions::Kaminari
def_delegators :@view, :link_to, :subject_path, :edit_subject_path, :image_tag, :subject_entries_path, :subject_issues_path, :subject_campaigns_path,
:subject_post_path, :organisation_path
def sortable_columns
# Declare strings in this format: ModelName.column_name
@sortable_columns ||= %w(Subject.last_name Subject.date_of_birth Subject.date_of_death Organisation.name GeneralCategory.name PoliticalCategory.name EconomicCategory.name)
end
def searchable_columns
# Declare strings in this format: ModelName.column_name
@searchable_columns ||= %w(Subject.first_name Subject.last_name Subject.date_of_birth Subject.date_of_death Organisation.name GeneralCategory.name PoliticalCategory.name EconomicCategory.name)
end
private
def data
records.map do |record|
[
# comma separated list of the values for each cell of a table row
# example: record.attribute,
link_to(image_tag(record.image.url(:micro, class: "subject_image")) + " #{ record.full_name }", subject_path(record), remote: true),
record.date_of_birth,
record.date_of_death,
display_organisation_link(record).join(', '),
record.general_categories.map(&:name).join(', '),
record.political_categories.map(&:name).join(', '),
record.economic_categories.map(&:name).join(', '),
record.aggregated_sentiment,
record.aggregated_relative_sentiment,
link_to('Edit', edit_subject_path(record), remote: true, class: "btn btn-primary btn-xs"),
link_to('Entries', subject_entries_path(record), class: "btn btn-primary btn-xs"),
link_to('Issues', subject_issues_path(record), class: "btn btn-primary btn-xs"),
link_to('Campaigns', subject_campaigns_path(record), class: "btn btn-primary btn-xs"),
link_to('Delete', record, method: :delete, data: { confirm: "Delete #{ record.full_name } ?" }, remote: true, class: "btn btn-danger btn-xs"),
link_to('Posts', subject_post_path(record), class: "btn btn-primary btn-xs")
]
end
end
def get_raw_records
# insert query here
Subject.includes(:organisations, :secondary_orgs, :general_categories, :political_categories, :economic_categories).references(:secondary_org, :general_categories, :political_categories, :economic_categories).distinct
#Subject.includes(:general_categories, org_posts: [:organisation, :secondary_org]).references(:secondary_org, :general_categories).distinct
end
def display_organisation_link(record)
record.all_active_organisations.map.each do |organisation|
if organisation.present?
link_to(organisation.name,
organisation_path(organisation), remote: true)
else
""
end
end
end
# ==== Insert 'presenter'-like methods below if necessary
end
And the coffeescript:
subjects_table = $('#subjects-table').DataTable
pageLength: 25
processing: true
pagingType: "full_numbers"
ajax: $('#subjects-table').data('source')
columnDefs: [ {
orderable: false,
targets: [7, 8, 9, 10, 11, 12, 13, 14]
} ]
A note that all the searching/sorting works perfectly (on both serverside and clientside), but only 10 records will ever be displayed if serverside is disabled.
After looking through the lib/ajax-datatables-rails/base.rb code, I decided to manually override the :length parameter to see if it fixed the limited records issue - sure enough it works.
There must be some sort of an issue preventing this value from being set properly when using clientside pagination.
ajax: {
dataType: 'json',
url: 'index'
data: (d) ->
d.dod_filter = subject_dod_filter
d.length = 100
return d
}
All it needed was to have this parameter specified. (Above sets to 100 records)
I am experiencing the same problem. Is there a resolution(besides the manual override?)
'start' is always Zero no matter which page I attempt to select. I am using ServerSide data and SimplePaginator(Same problem with Kaminari)
<<<<< Controller] -- Index -- Params: {"draw"=>"6", "columns"=>{"0"=>{"data"=>"0", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, "1"=>{"data"=>"1", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, "2"=>{"data"=>"2", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, "3"=>{"data"=>"3", "name"=>"", "searchable"=>"false", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}, "4"=>{"data"=>"4", "name"=>"", "searchable"=>"false", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}, "5"=>{"data"=>"5", "name"=>"", "searchable"=>"false", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}}, "order"=>{"0"=>{"column"=>"2", "dir"=>"desc"}}, "start"=>"0", "length"=>"100", "search"=>{"value"=>"", "regex"=>"false"}, "_"=>"1470615375314", "controller"=>"recipients", "action"=>"index", "format"=>"json"}
I am using version 0.2.1 of this gem & jquery-datatables-rails (3.0.0)
Thanks
I use rails (~> 4.0), kaminari (~> 0.15), ajax-datatables-rails (0.3.0) And when in my datatable I push any page, the json is always the same. Could you help me? tks