Change the number of displayed rows in jQuery datatable

后端 未结 4 590
南旧
南旧 2021-01-05 05:11

Why the number of rows in jquery datatable (see the code below) is not set to 5? It is equal to 10 8as by default). Why \'iDisplayLength\': 5 does

4条回答
  •  隐瞒了意图╮
    2021-01-05 05:45

    Try something like this. DataTables has built-in options that let you pull data from an AJAX source without trying to build it yourself. Read the documentation and customize it as needed:

    function loadData() {
        var oTable = $('#newspaper-b').dataTable({
                "sAjaxSource": 'modules/getData.php',
                "sPaginationType": "full_numbers",
                "aaSorting": [
                    [3, "asc"]
                ],
                "bJQueryUI": true,
                'iDisplayLength': 5,
                'bLengthChange': false
        });
    };
    

    To modify the table in some way after the data is loaded, you'll want to add the fnDrawCallback option:

     "fnDrawCallback": function( oSettings ) {
          // use jQuery to alter the content of certain cells
          $lastcell = $('#newspaper-b').find('tr').find('td:last');
          // manipulate it somehow
     }
    

提交回复
热议问题