In Rails 3.1 what is the recommended gem to integrate with DataTables ?
I'm using the jquery-datatables-rails
gem with bootstrap (twitter-bootstrap-rails gem) and it is perfect. The railscast episode on it is great -- but don't put the gem in your assets group or it will not work when deploying to heroku (since the assets group is not used in production).
Put this line in your gemfile:
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
and run:
bundle install
Also, make sure to put this line in your application.rb:
config.assets.initialize_on_precompile = false
Add this to your application.js
//= require dataTables/jquery.dataTables
And this one if you are using bootstrap:
//= require dataTables/jquery.dataTables.bootstrap
Add this to your application.css:
*= require dataTables/jquery.dataTables
Or this one if you are using bootstrap:
*= require dataTables/jquery.dataTables.bootstrap
And if you are using bootstrap add this to your js.coffee file for your controller you are using datatables in:
If you are using fluid containers:
#// For fluid containers
$('#dashboard').dataTable({
"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap"
});
If you are using fixed width containers:
#// For fixed width containers
$('.datatable').dataTable({
"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap"
});
In Ryan Bates' RailsCast on the topic (http://railscasts.com/episodes/340-datatables) he uses jquery-datatables-rails (https://github.com/rweng/jquery-datatables-rails)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With