jbox-web / ajax-datatables-rails

A wrapper around DataTable's ajax methods that allow synchronization with server-side pagination in a Rails app
MIT License
590 stars 227 forks source link

paginate_records fails #41

Closed kingp0dd closed 10 years ago

kingp0dd commented 10 years ago

Hi,

I've been trying to fix this but to no success. I am getting the following error while loading the ajax data:

DataTables warning: table id=projects-test - Ajax error. For more information about this error, please see http://datatables.net/tn/7

Upon checking the ajax response:

Please mixin a pagination extension
<header>
  <h1>
    AjaxDatatablesRails::Base::MethodNotImplementedError
      in ProjectsController#test
  </h1>
</header>

<div id="container">
  <h2>Please mixin a pagination extension.</h2>

  <div class="source">
<div class="info">
  Extracted source (around line <strong>#29</strong>):
</div>
<div class="data">
  <table cellpadding="0" cellspacing="0" class="lines">
      <tr>
        <td>
          <pre class="line_numbers">
<span>27</span>
<span>28</span>
<span>29</span>
<span>30</span>
<span>31</span>
<span>32</span>
          </pre>
        </td>
<td width="100%">
<pre>
<div class="line">
</div><div class="line">  def data
</div><div class="line active">    records.map do |record|
</div><div class="line">      [
</div><div class="line">        # comma separated list of the values for each cell of a table row
</div><div class="line">        # example: record.attribute,
</div>
</pre>
</td>
    </tr>
  </table>
</div>
</div>

My javascript looks like:

$('#projects-test').DataTable({
        "ajax": $('#projects-test').data('source'),
        "processing": true,
        "serverSide": true,
        "pagingType": "full_numbers",
        // optional, if you want full pagination controls.
        // Check dataTables documentation to learn more about
        // available options.
    });

Please shed some light. Thank you.

kingp0dd commented 10 years ago

I'm very sorry. Forgot to include pagination gems

antillas21 commented 10 years ago

Don't worry. Glad you could solve it :)

Anyway, the important thing is, if we can be of any help, don't hesitate in opening an issue or contacting us.

Cheers!

ghost commented 9 years ago

For those who get this, but do have the gems installed please do not forget to uncomment one of the lines: class MyDatatable < AjaxDatatablesRails::Base

uncomment the appropriate paginator module,

depending on gems available in your project.

include AjaxDatatablesRails::Extensions::Kaminari

include AjaxDatatablesRails::Extensions::WillPaginate

include AjaxDatatablesRails::Extensions::SimplePaginator

codemilan commented 9 years ago

hey I have uncommented the pagination module and tried for will_paginate and kaminari both, but sorting, searching, pagination are not working, whats the reason my code is https://github.com/antillas21/ajax-datatables-rails/issues/62

antillas21 commented 9 years ago

@coderawal can you try using the most basic of them? AjaxDataTablesRails::Extensions::SimplePaginator ? this will go directly to ActiveRecord methods.

antillas21 commented 9 years ago

@coderawal also, could you please remove this line from your controller?

respond_to :json, only: [:update]

Don't know (not sure) if the fact that you're limiting access to respond to json requests in any action that is not update may be causing the problem.

codemilan commented 9 years ago

Thnx antillas21, the problem was with key names in js files. I was using "bProcessing", "bServerSide", "sAjaxSource", "sPaginationType" instead of "processing", "serverSide", "ajax", "pagingType", doesn't both keys does same thing, got solution but i'm not clear why this short of behaviours.

antillas21 commented 9 years ago

@coderawal glad that you could debug it :smile:

You are right, both keys do the same thing... the difference comes from a change in the jquery.dataTables (plugin) API... keys that start with a hint on the value type they manage: bServerSide, sAjaxSource, sPaginationType, etc belong to the plugin's 1.9 version (now legacy), while the keys serverSide, processing, ajax, paginationType, etc belong to the plugin's 1.10 version (now current and stable).

We added some notes at the beginning of our gem's README to inform users about jquery.dataTables plugin changes in the API when this happened.