Show all rows not working

Show all rows not working

E_BrandaoE_Brandao Posts: 12Questions: 5Answers: 0
edited June 2020 in Free community support

My database has 1545 rows, when i define the page lenght as -1, i get teh following error "DataTables warning: table id=DataTables_Table_1 - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1", but when i put 1545 in the page lenght, it works.

  $(document).ready(function(){
    $('.table-log-notas').DataTable({
        "serverSide": true,
        "ajax": {
          "url": "../assets/php/functions/tabela-notas.php",
          "type": "POST"
        },
        responsive: true,
        "pageLength": -1,
        dom: 'Bfrtip',
        lengthMenu: [
            [ 10, 50, 100, 1000 ],
            [ '10 linhas', '50 linhas', '100 linhas', 'todas as linhas' ]
        ],
        buttons: [
            'excel', 'pdf','pageLength'
        ],
      //Definição dos textos que aparecerão na tabela
      "language": {
        "lengthMenu": "Mostrando _MENU_ registros por página",
        "zeroRecords": "Nada encontrado",
        "info": "Mostrando página _PAGE_ de _PAGES_",
        "infoEmpty": "Nenhum registro disponível",
        "infoFiltered": "(filtrado de _MAX_ registros no total)",
        "sSearch": "Pesquisar",
        "oPaginate": {
          "sNext": "Próximo",
          "sPrevious": "Anterior",
          "sFirst": "Primeiro",
          "sLast": "Último"
        },
        buttons: {
            pageLength: {
                _: "Mostrando %d linhas"
            }
        }
      },
      scrollY: 200,
      scroller: {
        loadingIndicator: true
      },
    });
  });

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    edited June 2020

    The -1 option applies to lengthMenu, not pageLength.

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,948
    Answer ✓

    When you use "pageLength": -1, with server side processing the length parameter sent to the server will be -1. Does you server script handle this properly?

    Kevin

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,948

    Should mention that using "pageLength": -1, you should disable server side processing as it is not helping reduce the number of rows. In fact it will cause a request to the server for each search and sort instead of just using the client for these functions.

    Kevin

  • E_BrandaoE_Brandao Posts: 12Questions: 5Answers: 0

    Thanks, was a problem in server side script, it was not handling this properly.

  • E_BrandaoE_Brandao Posts: 12Questions: 5Answers: 0
    edited June 2020

    To fix, i wrote in the server side script:

    if ($requestData['length'] == -1){
        $requestData['length'] = $qnt_linhas;
    }
    

    Obs.: the variable $qnt_linhas is the number of rows of the query

This discussion has been closed.