Datatables takes TOO much time

Datatables takes TOO much time

LESOURD2029LESOURD2029 Posts: 1Questions: 1Answers: 0
edited May 2018 in Free community support

Hello Everybody.
I have to launch 8 tables on a same page and it takes about 45 sec to load them but :
- Most of them are only 1 or 2 rows long, only one is more than 20 rows.
- Each request launched in toad are less than one sec to give answers even for the biggest.

I already tried processing, serverSide and deferLoading but no signifiant difference.

Please could you tell me why my request are going from 798ms in toad to 5 sec in jquery ???
What am i doing wrong ?

here is my js code :

    $('#' + table).dataTable({
      "bProcessing": true,
      destroy: true,
      paging: false,
      jQueryUI: false,
      autoWidth: false,
      //            processing      : true,
      //            serverSide      : true,
      //            "deferLoading"  : 10,
      pageLength: 20,
      lengthMenu: [20, 50, 100, "All"],
      responsive: true,
      oLanguage: {
        "sZeroRecords": "Aucun élément à afficher",
        "sLengthMenu": "Afficher _MENU_ éléments",
        "sProcessing": "Traitement en cours...",
        "sInfo": "Affichage de l'élement _START_ à _END_ sur _TOTAL_ éléments",
        "sInfoEmpty": "Affichage de l'élement 0 à 0 sur 0 éléments",
        "sInfoFiltered": "(filtré de _MAX_ éléments au total)",
        "sInfoPostFix": "",
        // "sSearch"        :"Rechercher:",
        "sUrl": "",
        "oPaginate": {
          "sFirst": "|<",
          "sPrevious": "<",
          "sNext": ">",
          "sLast": ">|"
        }
      },
      ajax: "php/listing_accueil.php?Couleur=" + table + "&date_saisie=" + $("#DateSaisie").val() + "&Matin_Aprem=" + $("input[class='MATIN_APREM']:checked").val(),
      dom: '',
      initComplete: function(settings, json) {
        $('.loader').fadeOut();
        $('.table_de_donnees').fadeIn("Slow");
      },
      "drawCallback": function(settings) {
        var iTotalRecords = settings.fnRecordsTotal();
        console.log(iTotalRecords);
        $('#Consultants' + table).html(iTotalRecords + ' <small class="text-right">CLAUDON R.</small>');
      }
    });

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Happy to take a look at a test case showing the issue.

    Allan

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @LESOURD2029 ,

    That does seem slow. One thing you could do, if all the tables follow the same config, is to move the initialisation options into the defaults so there's less to do at table setup. Something like this:

      $.extend( true, $.fn.dataTable.defaults, {
        "language": {
          "sLengthMenu": "Afficher _MENU_ éléments"
          ...
        }
      } );
    

    Another, though minor, optimisation if your data in each table doesn't change after the first load, would be to move the code in the drawCallback into the initComplete function.

    Hope that helps,

    Cheers,

    Colin

This discussion has been closed.