When export to pdf or another type of file, the totals is not printed, php mysql

When export to pdf or another type of file, the totals is not printed, php mysql

RicardoSanRicardoSan Posts: 6Questions: 1Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

Answers

  • kthorngrenkthorngren Posts: 22,041Questions: 26Answers: 5,083
    edited June 17

    Where are the totals?

    Please provide a link to a text case showing the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • RicardoSanRicardoSan Posts: 6Questions: 1Answers: 0

    this is my javascript

    <script type= "text/javascript">
    
    
      new DataTable('#tablita', {
        language: {
                url: 'js/es-ES.json',
            },
    
            columnDefs: [
      {
        targets: [5], // Aplica a las columnas 5
        orderable: false // Desactiva el ordenamiento para estas columnas
      }
    ],
    dom: 'Bfrtip',
                buttons: [
                    'copy', 'csv', 'excel','pdf','print'],
    
    footerCallback: function (row, data, start, end, display) {
        let api = this.api();
    
        // Remove the formatting to get integer data for summation
        let intVal = function (i) {
            return typeof i === 'string'
                ? i.replace(/[\$,]/g, '') * 1
                : typeof i === 'number'
                ? i
                : 0;
        };
    
        // Total over all pages
        total = api
            .column(3)
            .data()
            .reduce((a, b) => intVal(a) + intVal(b), 0);
        //Sumando la columna 4
        iivat = api
            .column(4)
            .data()
            .reduce((a, b) => intVal(a) + intVal(b), 0);
    
    
        // Total over this page
        pageTotal = api
            .column(3, { page: 'current' })
            .data()
            .reduce((a, b) => intVal(a) + intVal(b), 0);
        // sumando columna4    
        iivap = api
            .column(4, { page: 'current' })
            .data()
            .reduce((a, b) => intVal(a) + intVal(b), 0);
    
        // Update footer
        api.column(3).footer().innerHTML =
            'SubTotal pg.$' + pageTotal + ' ( $' + total  + 'Total S/Iva )';
        api.column(4).footer().innerHTML =
            'Total pg.$' + iivap + ' ( $' + iivat  + 'Total C/Iva )';
                }
    
        });
    
    </script>
    
  • RicardoSanRicardoSan Posts: 6Questions: 1Answers: 0
    edited June 18

    this is my php program

    <div>
        
        <table class="table table-hover table-condensed" id="tablita">
            <thead>
                <tr>
                  <th scope="col">Pedido</th>
                  <th scope="col">Fecha</th>
                  <th scope="col">Cliente</th>
                  <th scope="col">SubTotal</th>
                  <th scope="col">TOTAL</th>
                  <th scope="col">Accion </th>
                </tr>
            </thead>
        
           
            <tbody>
                <?php 
                $totalp=0;
                $iiva=0;
    
                 while ($datapedido = mysqli_fetch_array($queryped )){
                    $totalp=$totalp+$datapedido['subtotal'];  
                    $iiva=$iiva+$datapedido['iva_tax'];  
                
                ?>
                <tr>
                
                  <td><?php echo $datapedido['numped']; ?></td>
                  <td><?php echo $datapedido['fecha_ped']; ?></td>
                  <td><?php echo $datapedido['name']; ?></td>
                  <td><?php echo $datapedido['subtotal']; ?></td>
                  <td><?php echo $datapedido['subtotal']+$datapedido['iva_tax']; ?></td>
                  <td>
                    <a href="consultarpedido.php?np=<?= $datapedido['numped'] ?>"><button type="button" name="update" value ="ucliente" id="$datapedido['numped']" class="btn btn-primary btn-sm rounded-0 update" title="Consultar detalle" ><i class="fa fa-edit"></i></button></a>
                    <a href="eliped.php?np=<?= $datapedido['numped'] ?>"> <button type="button" name="delete" id="$datampedido['numped']" class="btn btn-danger btn-sm rounded-0 delete" title="Borrar" onclick= 'return confirmacion6()'><i class="fa fa-trash"></i></button></a>
                  </td>
                </tr>
                <?php 
                 }?>
              <!--
                <td><?php  echo "<tr>Sub-Total Pedidos =>>" .number_format($totalp, 2, ',', '.').""; ?></td>   
               <td><?php echo "<tr>Total IVA (Inc) =>>" .number_format($totalp+$iiva, 2, ',', '.')."";?> </td> 
                -->
                 
            </tbody>
            <tfoot>
            <tr>
                   <th> </th>
                  <th > </th>
                  <th > </th>
                  <th > </th>
                 <th> </th> 
                 
            </tr>
            </tfoot>
            
           </table>
        </div>
    
  • RicardoSanRicardoSan Posts: 6Questions: 1Answers: 0

    this is the screen

  • RicardoSanRicardoSan Posts: 6Questions: 1Answers: 0

    You can see the totals printed at the bottom of the page, but when I export to PDF or any other file that doesn't happen.

  • rf1234rf1234 Posts: 3,116Questions: 91Answers: 429
    edited June 18

    Have you set "footer" to true? In your code above you haven't.

    https://datatables.net/reference/button/excel

    Example from my own coding:

  • allanallan Posts: 64,599Questions: 1Answers: 10,683 Site admin

    @RicardoSan - Can you link to a test case please? That would let us see the full configuration, the versions being used, etc.

    Allan

  • RicardoSanRicardoSan Posts: 6Questions: 1Answers: 0

    The problem was solved, instead of using " dom: 'Bfrtip' " I used layout ,

    layout: {
    topStart: {
    buttons: [
    {extend:'copy',footer:true},
    {extend:'excel',footer:true},
    {extend:'pdf', footer:true}, 'colvis',
    {extend:'print',footer:true}]
    }
    },
    Thank you

  • rf1234rf1234 Posts: 3,116Questions: 91Answers: 429

    "layout" is certainly the newer option. But it also works with "dom" if you set "footer" to true.

    Glad you got it sorted!

Sign In or Register to comment.