How to show less than 10 rows??

How to show less than 10 rows??

cris_mfcris_mf Posts: 5Questions: 2Answers: 0

Hello, I try to show 5 rows per page, but i can't.
I try :
pageLength: 5
lengthMenu: [[5, 10, 20, -1], [5, 10, 20, "Todos"]]
but don´t work.

I think that I need a extra function but I don´t know. Please help me. Thanks

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583
    Answer ✓

    Hi cris_mf,

    Thank you for the question. I just tried this on http://live.datatables.net/dutabeye/1/edit, an easy to use sandpit for trying these things out, and it seems to do what you're after

    $(document).ready( function () {
      var table = $('#example').DataTable( {
        pageLength : 5,
        lengthMenu: [[5, 10, 20, -1], [5, 10, 20, 'Todos']]
      } )
    } );
    

    However, since it looks the same as what you sent across, can you give your setup a try there and see if it works. If not, please send across your DataTable code and we'll take a look.

    Cheers,

    Colin

  • cris_mfcris_mf Posts: 5Questions: 2Answers: 0
    edited December 2017

    Hi Colin,
    Thank you for response me. I tried your solution but it doesn't work.
    This is my code:

    var myTable = $("#tableCustomers").DataTable({
      ajax: "clientes/customerDatatable.php",
      language: spanish,
      columnDefs: [
        {
          targets: [0],
          visible: false,
          searchable: false,
          pageLength: 5,
          lengthMenu: [[5, 10, 20, -1], [5, 10, 20, "Todos"]]
        }
      ],
      columns: [
        { data: "id" },
        { data: "customer_name" },
        { data: "customer_surname1" },
        { data: "customer_surname2" },
        { data: "customer_phone" },
        {
          data: null,
          orderable: false,
          searchable: false,
          sortable: false,
          defaultContent: buttons
        }
      ]
    });
    
  • colincolin Posts: 15,112Questions: 1Answers: 2,583
    edited December 2017

    Hi again cris_mf,

    It looks like the problem is because you've put the pageLength and lengthMenu inside the columnDefs options block. I suspect if you move it to the top then that should solve your problem.

    On a different note, your language option isn't formatted correctly - this doesn't specify the spoken language as you have it, it defines language properties such as the thousand separator. See the link above for more information.

    Cheers,

    Colin

  • cris_mfcris_mf Posts: 5Questions: 2Answers: 0
    edited December 2017

    Thanks!!!
    And sorry, you can see that I am beginner.
    'spanish' is a variable, I think this way my code is more clean.

    var spanish ={"sProcessing": "Procesando...",
    "sLengthMenu": "Mostrar MENU registros",
    "sZeroRecords": "No se encontraron resultados",
    "sEmptyTable": "Ningún dato disponible en esta tabla",
    "sInfo": "Mostrando registros del START al END de un total de TOTAL registros",
    "sInfoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",
    "sInfoFiltered": "(filtrado de un total de MAX registros)",
    "sInfoPostFix": "",
    "sSearch": "Buscar:",
    "sUrl": "",
    "sInfoThousands": ",",
    "sLoadingRecords": "Cargando...",
    "oPaginate": {
    "sFirst": "Primero",
    "sLast": "Último",
    "sNext": "Siguiente",
    "sPrevious": "Anterior"
    },
    "oAria": {
    "sSortAscending": ": Activar para ordenar la columna de manera ascendente",
    "sSortDescending": ": Activar para ordenar la columna de manera descendente"
    }
    }

    I hope you understand me, my english isn't that good.
    Thank you!!
    Regards

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Excellent! Glad it's working. I'm a beginner too, this was my first support case!!! 100% happy customers so far :)

This discussion has been closed.