Convert sum of seconds on hh:mm:ss

Convert sum of seconds on hh:mm:ss

ScurreoScurreo Posts: 2Questions: 2Answers: 0

Hello, in column 5 of my table I am trying to add all the values and display them in the footer, however I have no results to return, knowing that I want to convert this number to hh: mm: ss. Can you help me ? Thank you

let table = $('#liste-intervention').DataTable({
                        'language': {
                            "sEmptyTable":     "Aucune donnée disponible dans le tableau",
                            "sInfo":           "Affichage de l'élément _START_ à _END_ sur _TOTAL_ éléments",
                            "sInfoEmpty":      "Affichage de l'élément 0 à 0 sur 0 élément",
                            "sInfoFiltered":   "(filtré à partir de _MAX_ éléments au total)",
                            "sInfoPostFix":    "",
                            "sInfoThousands":  ",",
                            "sLengthMenu":     "Afficher _MENU_ éléments",
                            "sLoadingRecords": "Chargement...",
                            "sProcessing":     "Traitement...",
                            "sSearch":         "Rechercher :",
                            "sZeroRecords":    "Aucun élément correspondant trouvé",
                            "oPaginate": {
                                "sFirst":    "Premier",
                                "sLast":     "Dernier",
                                "sNext":     "Suivant",
                                "sPrevious": "Précédent"
                            },
                            "oAria": {
                                "sSortAscending":  ": activer pour trier la colonne par ordre croissant",
                                "sSortDescending": ": activer pour trier la colonne par ordre décroissant"
                            },
                            "select": {
                                    "rows": {
                                        "_": "%d lignes sélectionnées",
                                        "0": "Aucune ligne sélectionnée",
                                        "1": "1 ligne sélectionnée"
                                    }  
                            }
                        },
                        'scrollX': true,
                        dom: 'Bfrtip',
                        buttons: [
                            'csv', 'excel'
                        ],
                        orderCellsTop: true,
                        initComplete: function () {
                            let api = this.api();
                            // Setup - add a text input to each header cell
                            $('.filterhead', api.table().header()).each(function() {
                                let title = $(this).text();
                            $(this).html('<input type="text" class="form-control column_search" placeholder="'+ title +'" />');
                            });
                        },
                        drawCallback: function() {
                            let api = this.api();
                            // $(api.table().footer()).html(
                            //     api.column(5,{ page: 'current' }).data().sum()
                            // );
                            // let totalIntervention = (new Date)
                            //                         .clearTime()
                            //                         .addSeconds(table.column(5).data().sum())
                            //                         .toString('HH:mm:ss');

                            // var totalIntervention = api
                            //     .column( 5 )
                            //     .data()
                            //     .reduce( function (a, b) {
                            //         return intVal(a) + intVal(b);
                            //     }, 0 );

                            let sum = table.column( 5 ).data().sum();
                            let convertSum = (new Date)
                                                    .clearTime()
                                                    .addSeconds(sum)
                                                    .toString('HH:mm:ss');
                                

                            $(api.column(0).footer()).html('Temps intervention total');
                            $(api.column(5).footer()).html(totalIntervention);

                        }
                    });

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    I would suggest using Moment.js, as it's excellent for all time/date based operations.

    Colin

This discussion has been closed.