Using Rails 3.1 with DataTables
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)
I haven't used it myself, but this is one that is available: https://github.com/gryphon/simple_datatables .
The following gem link may be relevant: https://github.com/artellectual/rails-datatables
This gem is a fork of the simple_datatables gem (mentioned by Allan) but it also supports pagination with kaminari and searching table data with ajax using the meta search gem.
精彩评论