Datatable only display 10 rows, when 50 asked

强颜欢笑 提交于 2021-01-29 02:42:43

问题


I want my datatable to display 50 rows per page.

I tried to set it with : bLengthChange: true and pageLength: 50 but it didn't work.

In an ideal world, I would also get rid of the bLengthChange -> false, so that I don't see the combo to select how much rows do I want...

Here is my code.

<html><body>
 <head>
     <link rel="stylesheet" href="//cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css">
</head>
<body>
<table class="table responsive table-togglable table-hover">
    <thead>
    <tr>
        <th data-toggle="true">ID</th>
        <th >Usuario</th>
        <th >Objeto</th>
        <th >Id del Objeto</th>
        <th class="none">Antes</th>
        <th class="none">Despues</th>
        <th >type</th>
        <th >Creaci&oacute;n</th>
        <th >Actualizaci&oacute;n</th>
    </tr>
    </thead>
    <tbody>
     <tr>
        <td>2165</td>
        <td> - </td>
        <td>PersonReferences</td>
        <td>3802973</td>
        <td> -  </td>
        <td> Large Text </td>
        <td>created</td>
        <td>2016-05-11 17:07:23</td>
        <td>2016-05-11 17:07:23</td>
        </tr>
  </tbody>
</table>

<script src="http://rh.dev/assets/materialize/js/jquery-1.11.2.min.js"></script>
<script src="http://rh.dev/assets/js/datatables/datatables.min.js"></script>
<script src="http://rh.dev/assets/js/datatables/extensions/responsive.min.js"></script>

    <script>
    $('.table-togglable').DataTable({
        bLengthChange: true,
        pageLength: 50,
        bInfo: false,
        responsive: true,
        "bAutoWidth": false,
    });
</script>

Any Idea?


回答1:


You can use iDisplayLength for DataTables 1.10+:

Number of rows to display on a single page when using pagination. If feature enabled (bLengthChange) then the end user will be able to override this to a custom setting using a pop-up menu.

$(".table-togglable").DataTable({
    bLengthChange: true,
    "lengthMenu": [ [10, 15, 25, 50, 100, -1], [10, 15, 25, 50, 100, "All"] ],
    "iDisplayLength": 50,
    bInfo: false,
    responsive: true,
    "bAutoWidth": false
});

Result: https://jsfiddle.net/cmedina/7kfmyw6x/50/



来源:https://stackoverflow.com/questions/37214235/datatable-only-display-10-rows-when-50-asked

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!