2

I followed https://github.com/rweng/jquery-datatables-rails exactly . Cannot get dataTables to work.

In index.html.erb

<table id = "funds12">
<thead>
  <tr>
    <th>Fund Name</th>
    <th>Category</th>
    <th>YTD</th>

  </tr>
</thead>
<tbody>
  <% @funds.each do |fund| %>
    <tr>
      <td><%= link_to "#{fund.scheme_name}", fund_path(fund.id) %><td>
      <td><%= fund.category %></td>
      <td><%= fund.fund_ytd %></td>
    </tr>
  <% end %>
 </tbody>
</table>


<script>
  $(document).ready(function() {
    $('#funds12').dataTable();
  } );

</script>

In application.js

//= require jquery
//= require turbolinks
//= require_tree .
//= require jquery_ujs
//= require dataTables/jquery.dataTables

In application.css.scss

*= require_self
 *= require_tree .
 *= require dataTables/jquery.dataTables

gem file

gem 'jquery-datatables-rails', git: 'git://github.com/rweng/jquery-datatables-rails.git'

Have tried a lot of options, only a table shows up with no functionalities of datatables. Using rails 4 Does the gem add new folders and files to your app, if so nothing is added in my app

2
  • no answers ??? any hint will also b of great help Commented Nov 28, 2013 at 13:50
  • post gem file? or part your inserted datatable gem Commented Jan 2, 2014 at 6:11

5 Answers 5

2

Turbolinks and Datatables can coexist if you can initialize the table on $(document).on "page:change" instead of $(document).ready as described here.

Sign up to request clarification or add additional context in comments.

Comments

0

I was having a similar problem earlier and had fixed it by carefully following this tutorial: http://railscasts.com/episodes/340-datatables?view=comments The author of this tutorial may not be using the same gem that you're using however this video is helpful either way.

Also, I'm curious to know if you've tried listing dataTables/jquery.dataTables higher up in your asset pipeline. If you're using Google Chrome try opening up your developer tools (F12), click the Resources tab, then click past the Frames folder and find and select Scripts. Here you'll find your scripts, in what order they've loaded and if there are any errors.

I hope this helps (even if a little bit)!

Comments

0

I was facing the same issue even after following ryan bates cast. Disabling turbolinks in rails4 or setting data-no-turbolink to true in the hyperlink addressing the page containing the table fixed the issue.

Comments

0

Not sure if this is the cause of your problem but this line needs to be at the end of the list.

//= require_tree .

Comments

0

There's an updated, separate branch that I referred to and was successfully in getting datatables to work with my Rails 4 app .... Try this out https://github.com/antillas21/ajax-datatables-rails/tree/v-0-4-0#customize-the-generated-datatables-class

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.