gulden PT
gulden PT

Reputation: 411

Using Rails 3.1 with DataTables

In Rails 3.1 what is the recommended gem to integrate with DataTables ?

Upvotes: 6

Views: 4184

Answers (4)

Ira Herman
Ira Herman

Reputation: 2826

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"
});

Upvotes: 10

Gareth Jones
Gareth Jones

Reputation: 1810

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)

Upvotes: 2

michaelh
michaelh

Reputation: 444

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.

Upvotes: 0

Allan
Allan

Reputation: 219

I haven't used it myself, but this is one that is available: https://github.com/gryphon/simple_datatables .

Upvotes: 0

Related Questions