[英]Using Rails 3.1 with DataTables
I'm using the jquery-datatables-rails
gem with bootstrap (twitter-bootstrap-rails gem) and it is perfect. 我正在使用
jquery-datatables-rails
gem和bootstrap(twitter-bootstrap-rails gem),它非常完美。 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). 关于它的railscast剧集很棒 - 但是不要将gem放在你的资产组中,否则在部署到heroku时它将不起作用(因为资产组不用于生产)。
Put this line in your gemfile: 把这一行放在你的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: 另外,请确保将此行放在application.rb中:
config.assets.initialize_on_precompile = false
Add this to your application.js 将其添加到您的application.js
//= require dataTables/jquery.dataTables
And this one if you are using bootstrap: 如果你使用bootstrap这一个:
//= require dataTables/jquery.dataTables.bootstrap
Add this to your application.css: 将其添加到您的application.css:
*= require dataTables/jquery.dataTables
Or this one if you are using bootstrap: 或者如果你使用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: 如果您使用bootstrap,请将此添加到您的控制器的js.coffee文件中,您使用的是数据表:
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"
});
在Ryan Bates关于该主题的RailsCast( http://railscasts.com/episodes/340-datatables )中,他使用了jquery-datatables-rails( https://github.com/rweng/jquery-datatables-rails )
我自己没有使用它,但这是可用的: https : //github.com/gryphon/simple_datatables 。
The following gem link may be relevant: https://github.com/artellectual/rails-datatables 以下gem链接可能是相关的: 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. 这个gem是simple_datatables gem的一个分支(由Allan提到),但它也支持使用kaminari进行分页,并使用meta search gem使用ajax搜索表数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.