Re-render pagination after change limit per page

6yoyoihd  于 2022-10-22  发布在  PHP
关注(0)|答案(1)|浏览(151)

I have a datatable :

$(document).ready (function() {
    $('#table_list').DataTable ({
        "bJqueryUI": true,
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "./action/list_json.php",
        "iDisplayLength": 50, // default nb to display 
        "aaSorting": [],
        "oLanguage": {
            "sLengthMenu": 'Show <select id="list"><option value="25">25</option><option value="50">50</option><option value="100">100</option></select> lines'
        },
        "aoColumns": [
            { "bVisible":false }, { "bSortable":false }, { "bSortable":false }, { "bSortable":false }, { "bSortable":false }
        ]
    });
}) ;

After changing the number of lines to display per page my back return good information :

....
"iTotalRecords" => "28"
"iTotalDisplayRecords" => 25

But in view I have a pagination with page 1 activated, normally I should have a pagination with 2 pages : 25 items on first page and 3 items on the second;
But I have something like:

The problem is that rendering of pagination is not done. What can I try next?

brc7rcf0

brc7rcf01#

you need to add below two attributes in datatable configuration

"bPaginate":true,
"sPaginationType":"full_numbers",

your code should look like

$(document).ready (function() {
    $('#table_list').DataTable ({
        "bJqueryUI": true,
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "./action/list_json.php",
        "bPaginate":true,
        "sPaginationType":"full_numbers",
        "iDisplayLength": 50, // default nb to display 
        "aaSorting": [],
        "oLanguage": {
            "sLengthMenu": 'Show <select id="list"><option value="25">25</option><option value="50">50</option><option value="100">100</option></select> lines'
        },
        "aoColumns": [
            { "bVisible":false }, { "bSortable":false }, { "bSortable":false }, { "bSortable":false }, { "bSortable":false }
        ]
    });
}) ;

NOTE: use "pagingType": "full_numbers" if "sPaginationType":"full_numbers" does not work. It depends on your datatable plugin version

相关问题