how to change page number datatable in outside dat

2019-08-12 06:32发布

问题:

I am using DataTables 1.10.4 with php and jquery. I want page numbers table with jquery but my code not Work? please helm me?

$(function(){

        dTable  =   $('#allProductsTbl').DataTable({
            "aLengthMenu": [[1, 50, 100, -1], [20, 50, 100, "همه"]],
            "responsive": true,
            "language": {
                "url": "../data/include/public/Persian.json"
            },
            "processing": true,
            "serverSide": true,
            "ajax":"products/op/dt_processing.php"
        });
        dTable.order( [ 3, 'desc' ] ).draw();
        //alert('pageNumber:'+dTable.page());
       dTable.page(3).draw(false);

    });

回答1:

SOLUTION

Use page() API method to set current page of the table. Note that page number is zero-based so page(3) opens 4th page.

For example:

$('#allProductsTbl').on('xhr.dt', function ( e, settings, json ) {
   var api = new $.fn.dataTable.Api(settings);
   api.page(3).draw(false);
});

var dTable = $('#allProductsTbl').DataTable({
   "aLengthMenu": [[1, 50, 100, -1], [20, 50, 100, "همه"]],
   "responsive": true,
   "language": {
      "url": "../data/include/public/Persian.json"
   },
   "processing": true,
   "serverSide": true,
   "ajax":"products/op/dt_processing.php",
   "order": [[ 3, 'desc' ]]
});

DEMO

See this jsFiddle for demonstration.