DataTables logo DataTables

server side processing with Rails
  • Hi everyone , I am farily new to databales and wanted to check is there a way I can use databales for a rails application , please advise if there is a tutorial a link some documenation I could use just like how you have for the php

  • There should be no barrier to using DataTables with a Rails application. The easiest way of doing this integration is just to have your Rails app output the JSON structure that DataTables needs on each draw. See for an example of server-side processing and what DataTables expects to get back from the server.

  • Allan thank you so much for your prompt reply, I was able to create a simple JSON structure in RoR. The second issue I have seems like its currently loading all the records in the HTML, how do I make it to not load all load all records. Please advise
  • You need to limit the number of records that your server-side script returns. DataTables sends a number of GET parameters which you can use to see what it is expected (sorting, filtering, length, start etc). From my link you will be able to see an example PHP script which does the server-side processing. You'll need to port something like that to RoR.

    The other option is just to load all of your rows (which sounds like is what is happening atm) and have DataTables use them on the client-side (just disabled the server-side processing flag). This will work well for smallish tables (upto 500 rows perhaps). After that server-side processing is probably better.

  • Hi Allan, seems like you are the owner of datatable.. so let me first congratulate you on making such a useful plugin that is universal in nature.

    I did some homework at my end and found out that in rails we can do the pagination using paginate commands.

    now the question is how do I integrate rails pagination with your plugin. I am pasting below the HTML that gets generated using the rails pagination.

    I am thinking I just need to wrap the <div class="pagination"> and <a> somewhere in the jquery .. please advise

    <div class="pagination"><span class="disabled prev_page">&laquo; Previous</span> <span class="current">1</span> <a href="/ticketlogs?page=2" rel="next">2</a> <a href="/ticketlogs?page=3">3</a> <a href="/ticketlogs?page=4">4</a> <a href="/ticketlogs?page=5">5</a> <a href="/ticketlogs?page=6">6</a> <a href="/ticketlogs?page=7">7</a> <a href="/ticketlogs?page=8">8</a> <a href="/ticketlogs?page=9">9</a> <span class="gap">&hellip;</span> <a href="/ticketlogs?page=64">64</a> <a href="/ticketlogs?page=65">65</a> <a href="/ticketlogs?page=2" class="next_page" rel="next">Next &raquo;</a></div>

  • Hi techy,

    It sounds like the code that you found is for pagination done in Rails with output to HTML. I don't think this is really what you want for DataTables integration. What you want to do is output the data in the JSON format that DataTables expects, as done in the link in my first post.

  • Hi guys,

    First I want to congratulate Allan with the awesome jquery plugin you developed.
    Secondly, I want to thank Chris Warren for the rails_datables plugin he published to simplify the live of a rails developer who want to use the benefits of both worlds.

    I am currently switching from the normal datatable setup to the :ajax_source options, because my dataset becomes to large.

    In the normal setup next to my object columns I also specified hyperlinks
    				<td><%= link_to 'Show', patient %></td>
    				<td><%= link_to 'Edit', edit_patient_path(patient) %></td>
    				<td><%= link_to 'Destroy', patient, :confirm => 'Are you sure ?', :method => :delete %></td>

    When I am now migrating to the :ajax_source option, the 'Show' and the 'Edit' link still work,
    But the 'Destroy' link troubles me. The "link_to 'Destroy', patient, :confirm => 'Are you sure ?', :method => :delete" statement generates inline javascript:
           '<a href="/patients/2" onclick="if (confirm('Bent u zeker?')) { var f = document.createElement('form'); = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);var s = document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', 'authenticity_token'); s.setAttribute('value', 'fjixNIJpUvrXzuzryFqyGtY/wKnwOTwpcS0d8UQF6DE='); f.appendChild(s);f.submit(); };return false;">Wis</a>'

    and the jquery datatables plugin doesn't like that.

    Could you give me a hint how to handle this issue ?
    I still want to ask the user for confirmation when, he decides to delete a patient.

    Thanks in advance.
This discussion has been closed.
All Discussions