2

I got datatables up and running, beautifully along with the nice jquery-ui as in the front page of datatables.

However, the main issue I'm having though is that I suck at CoffeeScript/JS

I'm trying to reload datatables every 1 second but don’t see any request coming into the webserver and hence no refreshes on the web page itself.

Here's my code:

app/assets/javascripts/comments.js.coffee

jQuery ->
  $('#comments_id').dataTable
    sPaginationType: "full_numbers"
    bJQueryUI: true
    bProcessing: true
    sAjaxSource: $('#coments')
  setInterval('$("#comments_id").dataTable().fnReloadAjax()', 3000);

It appears the setInterval callback is not being executred to redraw the table with fnDraw.

It seems I have the setInterval coding wrong.

Here is my the code in my app/view/comments/index.html.erb

<h1>Listing comments</h1>

<table id="comments_id" class="display">
<thead>
  <tr>
    <th>String</th>
  </tr>
</thead>
<% @comments.each do |comment| %>
<tbody>
  <tr>
    <td><%= comment.string %></td>
  </tr>
<% end %>
</tbody>
</table>

<br />

<%= link_to 'New Comment', new_comment_path %>

Help will be appreciated.

1
  • <grin> One up for complete honesty! </grin> Commented Apr 25, 2014 at 5:12

1 Answer 1

0

You have to set the sAjaxSource and instead of just redrawing the data table you should reload it:

.dataTable().fnReloadAjax();.

See: JQuery DataTables - AJAX Reloading Not Working

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

2 Comments

Hiya Ghommey: So I set sAjaxSource: $('#comments'). In the comment view, I have the table defined as follows <table id="comments_id" class="display". and I edited the last line in jQuery as follows...setInterval('$("#comments_id").dataTable().fnReloadAjax()', 3000);....I'm still not seeing requests being pushed through the server or any ajax reloads being done..... V_V....Thanks
sAjaxSource has to be a url

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.