<script>
   var da = function () {
        const api = this.api();
        const table = api.table(); // Datatable
        const $table = table.tables().nodes().to$(); // converti en dom Jquery

        const datas = api.ajax.json().data; // les données


        if (datas){
            const first = datas[0];
            const currency = (typeof first === 'object' && 'currency' in first)
                             ? first.currency : '';
            const totals_columns = [
                { name : 'subtotal' , value : getSum(datas,'subtotal')},
                { name : 'discount' , value : getSum(datas,'discount')},
                { name : 'tax' , value : getSum(datas,'tax')},
                { name : 'shipping' , value : getSum(datas,'shipping')},
                { name : 'total' , value : getSum(datas,'total')},
            ];

            //let columnsCount = table.columns().nodes().length;
            //let visible_columns = table.columns(":visible").nodes();

            if(totals_columns) {
                const cells = totals_columns.map(({name,value})=>{
                                                const d = {}
                                                d[name] =value
                                                return d
                                            })
                table.row.add(cells).draw(false);
                const cell = '<th class=\'total fs-14 border\'></th>'
                totals_columns.forEach((item,i)=>{
                    const column = table.column(item.name+':name',{page : 'current'});
                    const cells = column.to$();
                    //const td = jQuery(column.footer()).addClass('text-green');
                    cells.append(cell);
                    const td = cells.find('th.total:first-child');
                    td.addClass('text-green');
                    td.html(formatNumber(item.value,currency))
                })
            }

            table.columns.adjust()
            $table.find('tfoot').show()
        }else{
            $table.find('tfoot').hide();
        }



    }
    //$table.find('thead').remove()
</script>
