Please let me know how can i change the Page Length Dynamically??

Please let me know how can i change the Page Length Dynamically??

roverma2912roverma2912 Posts: 4Questions: 2Answers: 0

For Example if I have less than 500 rows then show All or if i have more than 500 rows then change the default page length to 500.

$(document).ready(function() {
var table = $('#nodeCardConfigurationTable').DataTable( {
"rowsGroup" : [0,1,9,2,8,3,7,4,6],
"columnDefs" : [ { orderable: false, targets: [1,2,3,4,5,6,7,8,9] } ],
"dom" : '<flp <t> i>',
"lengthMenu": [[-1, 500, 1000, 2000], ["All", 500, 1000, 2000 ]],
"drawCallback": function( settings ) {

            }
        } );
} );

how can i do it in drawCallBack or is there is any other way?

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    You can use the page.len() to set the page length.

    Kevin

  • roverma2912roverma2912 Posts: 4Questions: 2Answers: 0

    Thanks Kthorngren.. As i am new to datatables i have few more queries
    Please let me know how can i access page.len() in the drawCallBack function???

    And how can i get the total number of rows in drawCallBack ??

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin
    edited November 2017
    drawCallback: function () {
      var api = this.api();
      var len = api.page.len();
    }
    

    This is documented in the drawCallback reference documentation. See the example.

    And how can i get the total number of rows in drawCallBack ??

    page.info(). The full API documentation is available here.

    Allan

This discussion has been closed.