Can't change/set pageLength?

Can't change/set pageLength?

brybellbrybell Posts: 2Questions: 1Answers: 0
edited August 2016 in Free community support

Hello,

I have a table, here www.brybell.me/winelist_visa.html

I just want the table to default to 25 rows showing, but I want the user to still be able to change the number of rows displayed.

I know I need to use 'pageLength' but I can't seem to get it to work. I have tried adding it to my head on the HTML page, but nothing seems to work, it always only shows 10.

Answers

  • Peter HannaPeter Hanna Posts: 2Questions: 1Answers: 0
    edited August 2016

    One way to achieve this is to set the lengthMenu variable in the (document).ready call.

        $(document).ready(function ()
        {
            $('#table_id').DataTable({
                "lengthMenu": [[25, 30, 50, -1], [25, 30, 50, "All"]],
            });
        });//Close Document Ready Function
    
  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    You are attempting to initialise the same DataTable two different ways:

    <script type="text/javascript">$('#table_id').DataTable( {
      responsive: true
    } );
    </script>
    <script type="text/javascript">$('#table_id').DataTable( {
      pageLength: 25
    } );
    </script>
    

    See this section of the manual for how to initialise a table just once, with multiple options.

    Allan

  • brybellbrybell Posts: 2Questions: 1Answers: 0

    Ok thank you. I tried this and it is still not doing anything.

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    Seems to work for me. The attached image is what I get when I load the page - 25 records shown, per your pageLength option.

    Allan

This discussion has been closed.