1

I am using Datatables, and I get the data via AJAX (on my server side I have Rails).

Say that I want to share with another user, the page number 2 of one of the views that is using Datatables. Since the pagination is done with AJAX, there is no track of the page number in the URL, and therefore it can't be done.

How do you deal with pagination that is done via AJAX when you want to share a specific page (?page=1) ?

Thanks

blackghost
  • 683
  • 1
  • 8
  • 18

1 Answers1

1

DataTables provides the possibility of sending custom parameters in the AJAX call.

$(function () {
  var requestsTable = $('#my_table').DataTable({
    'processing': true,
    'serverSide': true,
    'searching': false,
    'ajax': {
      'url': '/my/ajax/callback',
      'type': 'GET',
      'data': function (d) {
        return $.extend({}, d, {
          'pageNum': $('#cachedPageNumInHiddenField').val()
        })
      }, "error": function () {
       alert("An unexpected error occurred.");
      }
    }
  ]
});

You will need to place a hidden input field on your page. Then hook a listener on the next and previous button's click events.

On how to hook a custom event on the page change please see thread Detect page change on DataTable .

Community
  • 1
  • 1
Marton Tatai
  • 180
  • 8