Total not visible for footerCallback on the live server

Total not visible for footerCallback on the live server

dannerbamdannerbam Posts: 11Questions: 1Answers: 0

Sorry for my english. Google translator!

I have included a datatable that also works great. Now I want to display the totals. Unfortunately that doesn't work. The sum is displayed in the console log, as well as in live.datatables.net, but not on the live server.
Maybe someone can help me and knows what's to blame. Unfortunately I can't figure it out.
What I have to add, the data comes from a mySQL database.

Here is the example on the datatables test server:
live.datatables.net/majajoqa/1/edit

And here is the script from the live server::

$(document).ready(function() {
  $('#datatable').DataTable({
      "lengthMenu": [[25,50,100,500,-1], [25,50,100,500,"Alle"]],
      /* "dom": 'lBfrtip', */ //Formatierung
      "dom": "<'row'<'col-sm-12 col-md-6'lB><'col-sm-12 col-md-6'f>>" +
      "<'row'<'col-sm-12'tr>>" +
      "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
      "buttons": [
        {
          extend: 'searchPanesClear',
          text: 'Projekt hinzufügen',
          className: 'btn btn-sm btn-gruen2 mt-2',
          attr: {
            'data-toggle': 'collapse',
            'href' : '#kundenformularaufklappen',
          }
        },
        {
          text: ' ',
          className: 'btn btn-sm btn-light mt-2',
          action: function ( e, dt, button, config ) {
            window.location = '#';
          }
        },
        {
          extend: 'print',
          text: 'drucken',
          className: 'btn btn-sm btn-orange1 mt-2',
          autoPrint: true,
          exportOptions: {
              columns: ':visible'
          }
        },
        {
            extend: 'print',
            text: 'selektierte drucken',
            className: 'btn btn-sm btn-orange2 mt-2',
            autoPrint: true,
            exportOptions: {
                columns: ':visible'
            }
        },
        {
          text: ' ',
          className: 'btn btn-sm btn-light mt-2',
          action: function ( e, dt, button, config ) {
            window.location = '#';
          }
        },
        {
          text: 'Controlling',
          className: 'btn btn-sm btn-prim1 mt-2',
          action: function ( e, dt, button, config ) {
            window.location = '?sb=ee_lager&sp=0';
          }
        },
        {
          text: 'Adressen',
          className: 'btn btn-sm btn-prim2 mt-2',
          action: function ( e, dt, button, config ) {
            window.location = '?sb=ee_lager&sp=1';
          }
        },
        {
          text: 'Infos',
          className: 'btn btn-sm btn-prim3 mt-2',
          action: function ( e, dt, button, config ) {
            window.location = '?sb=ee_lager&sp=2';
          }
        }
      ],
      select: true,
      colReorder: true,
      "language": {
        "select": {
          rows: {
              _: "%d Projekte ausgewählt",
              0: "Projekte anklicken um sie auszuwählen",
              1: "1 Projekt ausgewählt"
          }
        },
        "emptyTable":     "Keine Daten in Tabelle vorhanden",
        "zeroRecords":    "Keine passenden Einträge gefunden",
        "lengthMenu": "Zeige _MENU_ Einträge pro Seite",
        "info": "Zeige Seite _PAGE_ von _PAGES_ (_TOTAL_ Einträge gesamt),",
        /* "info":           "Zeige _START_ bis _END_ von _TOTAL_ Einträgen", */
        "infoEmpty": "Keine Einträge Verfügbar",
        "search":         "Suche:",
        "infoFiltered": "(gefiltert von _MAX_ Einträgen)",
        "paginate": {
            "first":      "Erste",
            "last":       "Letzte",
            "next":       "Nächste",
            "previous":   "Vorige"
        },
      }, 
      "columnDefs": [  // Spalten ausblenden
        {
            target: [0],
            //visible: false,
            searchable: true,
        },
      ],
      /* order: [[18, 'desc'], [5, 'asc'], [1, 'asc']], */

      "footerCallback": function ( row, data, start, end, display ) {
        var api = this.api(), data;

        // Remove the formatting to get integer data for summation
        var intVal = function ( i ) {
            return typeof i === 'string' ?
                i.replace(/[\€,]/g, '')*1 :
                typeof i === 'number' ?
                    i : 0;
        };

        // Total over all pages
        total = api
            .column( 22 )
            .data()
            .reduce( function (a, b) {
                return intVal(a) + intVal(b);
            }, 0 );

        // Total over this page
        pageTotal = api
            .column( 22, { page: 'current'} )
            .data()
            .reduce( function (a, b) {
                return intVal(a) + intVal(b);
            }, 0 );

        // Update footer
        $( api.column( 22 ).footer() ).html(
            '€ '+pageTotal +' ( € '+ total +' total)'
        );
      }
  } );
  console.log(pageTotal);
  console.log(total);
} );

The output from the console:

187790.13999999998     datatable_projekte.js:141 
187790.13999999998     datatable_projekte.js:142 

Maybe someone can also say in passing why the sum is not 187790.14 but 187790.13999999998?

I will send the corresponding php code in the next post

Thanks in advance.
Johann

This question has an accepted answers - jump to answer

Answers

  • dannerbamdannerbam Posts: 11Questions: 1Answers: 0

    Here the php page from the datatable from the live server: (PART 1)

    <table id="datatable" class="datatable table border-top table-hover table-sm">
                  <thead>
                    <tr>
                      <th style="display:none">ID</th>
                      <th class="">Projektnr</th>
                      <th></th>
                      <th style="<?=($sp==1?'':'display:none')?>">Strathek</th>
                      <th class="">Projekt</th>
                      <th style="<?=($sp==1?'':'display:none')?>">Anschrift</th>
                      <th style="<?=($sp==1?'':'display:none')?>">Anschrift2</th>
                      <th style="<?=($sp==1?'':'display:none')?>">PLZ</th>
                      <th style="<?=($sp==1?'':'display:none')?>">Ort</th>
                      <th class="text-center" style="<?=($sp==1?'':'display:none')?>">Aktiv</th>
                      <th class="text-center" style="<?=($sp==0?'':'display:none')?>" data-toggle="tooltip" title="Besichtigt">Bes.</th>
                      <th style="<?=($sp==2?'':'display:none')?>">eingetragen/aktiviert</th>
                      <th class="text-center" style="<?=($sp==0?'':'display:none')?>" data-toggle="tooltip" title="Auftrag">A</th>
                      <th class="text-center" style="<?=($sp==0?'':'display:none')?>" data-toggle="tooltip" title="Zählpunkt">ZP</th>
                      <th class="text-center" style="<?=($sp==0?'':'display:none')?>" data-toggle="tooltip" title="Förderung">FÖ</th>
                      <th class="text-center" style="<?=($sp==0?'':'display:none')?>" data-toggle="tooltip" title="Fertigstellungsmeldung">FM</th>
                      <th class="text-center" style="<?=($sp==0?'':'display:none')?>" data-toggle="tooltip" title="Rechnung">RG</th>
                      <th class="text-center" style="<?=($sp==0?'':'display:none')?>" data-toggle="tooltip" title="DOKU">Doku</th>
                      <th class="text-center" style="<?=($sp==0?'':'display:none')?>">Fertig</th>
                      <th style="<?=($sp==2?'':'display:none')?>">Kommentar</th>
                      <th style="<?=($sp==2?'':'display:none')?>">Notizen</th>
                      <th style="<?=($sp==0?'':'display:none')?>">Größe in KWp</th>
                      <th style="<?=($sp==0?'':'display:none')?>">Angebotssumme</th>
                      <th class="text-center">Aktionen</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php
                      $sql = "SELECT * FROM lag_projekte ORDER BY projekte_nr";     
                  
                      foreach ($pdo->query($sql) as $row) {  
                        $kd_id = $row['id'];                   
                        $projekte_nr = $row['projekte_nr'];
                        $projekt_strathek = $row['projekt_strathek'];
                        $projekt_name = $row['projekt_name'];
                        $projekt_anschrift = $row['projekt_anschrift'];
                        $projekt_anschrift2 = $row['projekt_anschrift2'];
                        $projekt_plz = $row['projekt_plz'];
                        $projekt_ort = $row['projekt_ort'];
                        $anl_groesse = number_format($row['anl_groesse'], 2, ",", ".");
                        /* $angebotssumme = ($row['angebotssumme']); */
                        /* $angebotssumme = number_format($row['angebotssumme'], 2, ",", "."); */
                        $angebotssumme = number_format($row['angebotssumme'], 2, ".", ",");
                        /* $angebotssumme = (double)$angebotssumme; */
                        $kommentar = $row['kommentar'];
                        $notizen = $row['notizen'];
                        $aktiv = $row['aktiv'];
                        $besichtigt = $row['besichtigt'];
                        $beauftragt = $row['beauftragt'];
                        $datum = $row['datum'];
                        $zählpunkt = $row['zählpunkt'];
                        $zp_datum = $row['zp_datum'];
                        $förderung = $row['förderung'];
                        $fo_datum = $row['fo_datum'];
                        $fmt = $row['fertigstellungsmeldung'];
                        $rg = $row['rechnung'];
                        $doku = $row['doku'];
                        $fertig = $row['fertig'];
                        $lag_kunden_id = $row['lag_kunden_id'];
    
                        $ja = "<label style='display:none'>1</label><i class='far fa-check-circle text-success'></i>";
    
                        $aktiv_ja = '<a class="" href="#" role="button" data-toggle="tooltip" title="Projekte werden nach 6 Monaten automatisch deaktiviert"><label style="display:none">1</label><i class="far fa-check-circle text-success"></i></a>';
    
                        // Zählpunkt Buttons
                          if($zählpunkt==0){
                            $zp = '<label style="display:none">0</label><a class="" href="?zp0='.$kd_id.'" role="button" data-toggle="tooltip" title="Zählpunkt eintragen"><i class="far fa-times-circle text-danger"></i></a>';
                          }else if($zählpunkt==1){
                            $zp = "<label style='display:none'>1</label><a class='' href='?zp1=".$kd_id."' role='button' data-toggle='tooltip' title='Zählpunkt beantragt -> erhalten eintragen'><i class='far fa-times-circle text-warning'></i></a><p class='datum_margin'><em>".date('d.m.Y', strtotime($zp_datum))."</em></p>";
                          }else if($zählpunkt==2){
                            $zp = "<label style='display:none'>2</label><i class='far fa-check-circle text-success'></i><p class='datum_margin'><em>".date('d.m.Y', strtotime($zp_datum))."</em></p>";
                          }
                        // / Zählpunkt Buttons
    
                        // Förderung Buttons
                          if($förderung==0){
                            $fo = '<label style="display:none">0</label><a class="" href="?fo0='.$kd_id.'" role="button" data-toggle="tooltip" title="Förderung Beantragt eintragen"><i class="far fa-times-circle text-danger"></i></a>';
                          }else if($förderung==1){
                            $fo = "<label style='display:none'>1</label><a class='' href='?fo1=".$kd_id."' role='button' data-toggle='tooltip' title='Förderung beantragt -> erhalten eintragen'><i class='far fa-times-circle text-warning'></i></a><p class='datum_margin'><em>".date('d.m.Y', strtotime($fo_datum))."</em></p>";
                          }else if($förderung==2){
                            $fo = "<label style='display:none'>2</label><i class='far fa-check-circle text-success'></i><p class='datum_margin'><em>".date('d.m.Y', strtotime($fo_datum))."</em></p>";
                          }
                        // / Förderung Buttons
    
                        // Fertigstellungsmeldung Buttons
                          if($fmt==0){
                            $fm = '<label style="display:none">0</label><a class="" href="?fm0='.$kd_id.'" role="button" data-toggle="tooltip" title="Fertigstellungsmeldung Beantragt eintragen"><i class="far fa-times-circle text-danger"></i></a>';
                          }else if($fmt==1){
                            $fm = "<label style='display:none'>1</label><a class='' href='?fm1=".$kd_id."' role='button' data-toggle='tooltip' title='Fertigstellungsmeldung beantragt -> erhalten eintragen'><i class='far fa-times-circle text-warning'></i></a>";
                          }else if($fmt==2){
                            $fm = "<label style='display:none'>2</label><i class='far fa-check-circle text-success'></i>";
                          }
                        // / Fertigstellungsmeldung Buttons
    
                        $aktiv_nein = '<a class="" href="?akt='.$kd_id.'" role="button" data-toggle="tooltip" title="Projekt wieder aktivieren"><label style="display:none">0</label><i class="far fa-times-circle text-danger"></i></a>';
                        
                        $nein = '<label style="display:none">0</label><i class="far fa-times-circle text-danger"></i>';
    
                        $textaktivformat = $aktiv==0?"text-decoration: line-through;color: #bbbbbb;":"";
    
                        // KONTAKTE pro Projekt zählen
                        $sql5 = $pdo->prepare("SELECT *, COUNT(*) AS anzahlkontakte FROM lag_projekte, lag_projekte_kontakte 
                                                WHERE lag_projekte_kontakte.lag_projekte_id = lag_projekte.id
                                                AND lag_projekte.id = $kd_id");
                        $sql5->execute();  
                        $row5 = $sql5->fetch();
                    ?>
    
  • dannerbamdannerbam Posts: 11Questions: 1Answers: 0
    edited January 2023

    Here the php page from the datatable from the live server: (PART 2)

    <tr>
                        <td style="display:none"><label style="<?=$textaktivformat?>"><?=$kd_id?></label></td>
                        <td class=""><label style="<?=$textaktivformat?>"><?=$projekte_nr?></label></td>
                        <td>
                          <span class="badge rounded-pill <?=$row5['anzahlkontakte']==0?"bg-light":"bg-primary"?>">
                            <?=$row5['anzahlkontakte']?> Kontakte
                          </span>
                        </td>
                        <td style="<?=($sp==1?'':'display:none')?>"><label style="<?=$textaktivformat?>"><?=$projekt_strathek?></label></td>
                        <td><label style="<?=$textaktivformat?>"><?=$projekt_name?></label></td>
                        <td style="<?=($sp==1?'':'display:none')?>"><label style="<?=$textaktivformat?>"><?=$projekt_anschrift?></label></td>
                        <td style="<?=($sp==1?'':'display:none')?>"><label style="<?=$textaktivformat?>"><?=$projekt_anschrift2?></label></td>
                        <td style="<?=($sp==1?'':'display:none')?>"><label style="<?=$textaktivformat?>"><?=$projekt_plz?></label></td>
                        <td style="<?=($sp==1?'':'display:none')?>"><label style="<?=$textaktivformat?>"><?=$projekt_ort?></label></td>
                        <td class="text-center" style="<?=($sp==1?'':'display:none')?>"><?= $aktiv==1?$aktiv_ja:$aktiv_nein ?></td>
                        <td class="text-center" style="<?=($sp==0?'':'display:none')?>"><?= $besichtigt ?> <a class="btn text-primary btn-sm besichtigungbtn" href="#" role="button" data-toggle="tooltip" title="Besichtigungsdatum eintragen/ändern"><i class="fas fa-calendar-plus"></i></a></td>
    <td style="<?=($sp==2?'':'display:none')?>"><?= $datum ?></td>
                        <td class="text-center" style="<?=($sp==0?'':'display:none')?>"><?= $beauftragt==0?'<a href="?sb=ee_lager&kd_id='.$kd_id.'&beauftragt=1" role="button" data-toggle="tooltip" title="Beauftragung eintragen"><i class="far fa-times-circle text-danger"></i></a>':'<a href="#" role="button"><i class="far fa-check-circle text-success" data-toggle="tooltip" title="Auftrag vorhanden"></i></a>' ?></td>
                        <td class="text-center" style="<?=($sp==0?'':'display:none')?>"><?= $zp ?></td>
                        <td class="text-center" style="<?=($sp==0?'':'display:none')?>"><?= $fo ?></td>
                        <td class="text-center" style="<?=($sp==0?'':'display:none')?>"><?= $fm ?></td>
                        <td class="text-center" style="<?=($sp==0?'':'display:none')?>"><?= $rg==0?'<a href="?sb=ee_lager&kd_id='.$kd_id.'&rg=1" role="button" data-toggle="tooltip" title="Rechnung eintragen"><i class="far fa-times-circle text-danger"></i></a>':'<a href="#" role="button"><i class="far fa-check-circle text-success" data-toggle="tooltip" title="Rechnung wurde gestellt"></i></a>' ?></td>
                        <td class="text-center" style="<?=($sp==0?'':'display:none')?>"><?= $doku==0?'<a href="?sb=ee_lager&kd_id='.$kd_id.'&doku=1" role="button" data-toggle="tooltip" title="DOKU eintragen"><i class="far fa-times-circle text-danger"></i></a>':'<a href="#" role="button"><i class="far fa-check-circle text-success" data-toggle="tooltip" title="DOKU wurde erstellt"></i></a>' ?></td>
                        <td class="text-center" style="<?=($sp==0?'':'display:none')?>"><?= $fertig==1?$ja:$nein ?></td>
                        <td style="<?=($sp==2?'':'display:none')?>"><?= $kommentar ?></td>
                        <td style="<?=($sp==2?'':'display:none')?>"><?= $notizen ?></td>
                        <td class="text-end" style="<?=($sp==0?'':'display:none')?>"><label style="<?=$textaktivformat?>"><?=$anl_groesse?></label></td>
                        <td class="text-end" style="<?=($sp==0?'':'display:none')?>"><?=$angebotssumme?></td>
                        <td class="text-center">
                        <?php 
                        // Prüfen ob bei Projekt schon abgeschlossen werden kann, ob Montageschein Artikelpositionen mit der Anzahl ausgeliefert übereinstimmt
                        $bvhnr = $_SESSION['bvh'];
                        $sql6 = $pdo->prepare("SELECT sum(ausgeliefert) ausgeliefert
                                                FROM lag_montageschein
                                                    WHERE ms_nr ='$bvhnr'");
                        $sql6->execute();  
                        $row6 = $sql6->fetch();
    
                        $sql7 = $pdo->prepare("SELECT sum(ab_kommissioniert) kommissioniert
                                                FROM lag_angebote
                                                    WHERE ab_nr ='$bvhnr'");
                        $sql7->execute();  
                        $row7 = $sql7->fetch();
                        
                          if($fertig==0){
                            if($fmt!=2){
                              $pdferstellen = '<a class="btn btn-light text-secondary btn-sm border border-secondary" href="#" role="button" data-toggle="tooltip" title="zuerst Fertigstellungsmeldung eintragen"><i class="far fa-file-pdf"></i></a>';
                            }else{
                              if($row7['kommissioniert']==$row6['ausgeliefert']){
                                $pdferstellen = '<a class="btn btn-light text-danger btn-sm border border-danger" href="kundefertig-pdf.php?kf='.$kd_id.'" role="button" data-toggle="tooltip" title="PDF erstellen und Projekt abschließen" target="_blank"><i class="far fa-file-pdf"></i></a>';
                              }else{
                                $pdferstellen = '<a class="btn btn-light text-warning btn-sm border border-warning" href="#" role="button" data-toggle="tooltip" title="nicht alle Artikel ausgeliefert"><i class="far fa-file-pdf"></i></a>';
                              }
                              
                            }
                          }else{
                            $pdferstellen = '<a class="btn btn-success text-light btn-sm" href="kundefertig-pdf.php?kf='.$kd_id.'" role="button" data-toggle="tooltip" title="PDF anzeigen" target="_blank"><i class="far fa-file-pdf"></i></a>';
                          }
    
  • dannerbamdannerbam Posts: 11Questions: 1Answers: 0

    Here the php page from the datatable from the live server: (PART 3)

    $pdferstellen_kB = '<a class="btn btn-light text-secondary btn-sm border border-secondary" role="button" data-toggle="tooltip" title="keine Berechtigung zum PDF erstellen und Projekt abschließen" target="_blank"><i class="far fa-file-pdf"></i></a>';
                          $bearbeiten = '<a class="btn btn-warning btn-sm editbtn" href="" role="button" data-tooltip="tooltip" title="Projekt bearbeiten" data-toggle="modal" data-target="#lieferantaendern"><i class="fas fa-pencil-alt"></i></a>';
                          $bearbeiten_kB = '<a class="btn btn-secondary btn-sm" role="button" data-toggle="tooltip" title="keine Berechtigung zum bearbeiten"><i class="fas fa-pencil-alt"></i></a>';
                          $delete = '<a class="btn btn-danger btn-sm" href="?delete='.$kd_id.'" role="button" data-toggle="tooltip" data-placement="left" title="Löschen"><i class="far fa-trash-alt"></i></a>';
                          $delete_kB = '<a class="btn btn-secondary btn-sm" role="button" data-toggle="tooltip" title="keine Berechtigung zum löschen"><i class="far fa-trash-alt"></i></a>';
                          $kontaktplus = '<a class="btn btn-prim1 btn-sm" href="?sb=ee_lager&kdkadd='.$kd_id.'" role="button" data-tooltip="tooltip" title="Kontakt hinzufügen"><i class="fas fa-user-plus"></i></a>';
                          $kontaktplus_kB = '<a class="btn btn-secondary btn-sm" role="button" data-toggle="tooltip" title="keine Berechtigung zum hinzufügen von Kontakten"><i class="fas fa-user-plus"></i></a>';
                          $kontaktanzeigen = '<a class="btn btn-prim2 btn-sm" href="?sb=ee_lager&kdksee='.$kd_id.'" role="button" data-tooltip="tooltip" title="Kontakte anzeigen"><i class="fas fa-users"></i></a>';
                          $projektdetails = '<a class="btn btn-warning btn-sm projektdetailbtn" href="" role="button" data-tooltip="tooltip" title="Projektdetails ansehen" data-toggle="modal" data-target="#projektdetailmodal"><i class="fas fa-info-circle"></i></a>';
    
                          if($_SESSION['role']=="LESEN"){
                            echo $pdferstellen_kB." | ".$projektdetails." ".$kontaktplus_kB." ".$kontaktanzeigen." | ".$bearbeiten_kB." ".$delete_kB; ?>
                          <?php }elseif($_SESSION['role']=="BEARBEITEN"){
                            echo $pdferstellen." | ".$projektdetails." ".$kontaktplus." ".$kontaktanzeigen." | ".$bearbeiten." ".$delete_kB ; ?>
                          <?php }elseif($_SESSION['role']=="SCHREIBEN" || $_SESSION['role']=="SUPERADMIN" || $_SESSION['role']=="ADMIN"){                      
                            echo $pdferstellen." | ".$projektdetails." ".$kontaktplus." ".$kontaktanzeigen." | ".$bearbeiten." ".$delete;
                          } ?>
                        </td>
                      </tr>
                  
                    <?php }//endforeach;?>
                  </tbody>
                  <tfoot style="<?=($sp==0?'':'display:none')?>">
                      <tr>
                          <th colspan="13" style="text-align:right">Total:</th>
                          <th></th>
                      </tr>
                  </tfoot>
                </table>
    
  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    You are trying to update the footer for column 22:

            $( api.column( 22 ).footer() ).html(
                '€ '+pageTotal +' ( € '+ total +' total)'
            );
    

    But only have 14 columns defined in the footer:

                  <tfoot style="<?=($sp==0?'':'display:none')?>">
                      <tr>
                          <th colspan="13" style="text-align:right">Total:</th>
                          <th></th>
                      </tr>
                  </tfoot>
    

    Either use api.column( 13 ).footer() to select the last th you defined or create more columns in the footer.

    Kevin

  • dannerbamdannerbam Posts: 11Questions: 1Answers: 0

    The table has 24 columns. A few of them are hidden with "display:none". You can see in Post 2.

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    The point being that the selector $( api.column( 22 ).footer() ) is not finding a corresponding th because there is not a corresponding th defined in the footer. It might be easiest to just at an id attribute to the th you want the total displayed and use that as the selector.

    Kevin

  • dannerbamdannerbam Posts: 11Questions: 1Answers: 0

    According to the console output, the sum is calculated, just not displayed.
    That's the strange thing.

  • dannerbamdannerbam Posts: 11Questions: 1Answers: 0

    Output from Console:

    187790.13999999998     datatable_projekte.js:141
    187790.13999999998     datatable_projekte.js:142
    
  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    edited January 2023

    The problem isn't with the code performing the sum. The problem is the jQuery selector ($( api.column( 22 ).footer() )) isn't finding an element in the DOM so its not displaying the total.

    Go to your console and type this $( $('#datatable').DataTable().column( 22 ).footer() ).length. What is the result?

    Do you get something like this?

    Uncaught TypeError: Cannot read properties of undefined (reading 'nTf')

    Now try $( $('#datatable').DataTable().column( 1 ).footer() ).length. You should see 1 in the console.

    Kevin

  • dannerbamdannerbam Posts: 11Questions: 1Answers: 0
    VM19234:1 Uncaught ReferenceError: api is not defined
        at <anonymous>:1:4
    
  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    VM19234:1 Uncaught ReferenceError: api is not defined
    at <anonymous>:1:4

    When does this occur?

    Kevin

  • dannerbamdannerbam Posts: 11Questions: 1Answers: 0

    Sorry, i was too fast.

    By typing this

    $( $('#datatable').DataTable().column( 22 ).footer() ).length
    

    the result i "0"

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    edited January 2023 Answer ✓

    Ok. Like I said the selector is not finding the DOM element because you haven't defined it in the footer. My suggestion is to use the id attribute on the th where you want the total displayed and update your selector accordingly.

    for example:

    <tfoot style="<?=($sp==0?'':'display:none')?>">
        <tr>
            <th colspan="13" style="text-align:right">Total:</th>
            <th id="myTotal"></th>
        </tr>
    </tfoot>
    
    $( "#myTotal" ).html(
        '€ '+pageTotal +' ( € '+ total +' total)'
    );
    

    Kevin

  • dannerbamdannerbam Posts: 11Questions: 1Answers: 0

    Yessss!! Thank you!

    Output in the Table
    Total: € 187790.13999999998 ( € 187790.13999999998 total)

    Can I format the sum with 2 decimal places? It's miscalculated here.

    Thank you very much!!

  • dannerbamdannerbam Posts: 11Questions: 1Answers: 0
    (pageTotal.toFixed(2))
    

    OK?

Sign In or Register to comment.