Use number render on total values in footer

Use number render on total values in footer

martin1223345martin1223345 Posts: 84Questions: 23Answers: 0

Hopefully my last question.. (sorry for al the questions)

I managed to get a total row in my footer that workes perfectly. I have tried to apply the folowing number render but no mather where i place it nothing works. Does anyone know how to aply this to the total output values?

$.fn.dataTable.render.number( '.', '.', 0 )

The total footer function where i need the output to be 5.000.000 instead of 5000000:

"footerCallback": function ( row, data, start, end, display ) {
            var api = this.api(), data;
 
            // converting to interger to find total
            var intVal = function ( i ) {
                return typeof i === 'string' ?
                    i.replace(/[\$,]/g, '')*1 :
                    typeof i === 'number' ?
                        i : 0;
            };
 
            // computing column Total of the complete result 
                
        var bulletTotal = api
                .column( 3,{page:'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
                
            var leadTotal = api
                .column( 7, {page:'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
                
         var cashTotal = api
                .column( 8, {page:'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
                
        
            
                
            // Update footer by showing the total with the reference of the column index 
        $( api.column( 0 ).footer() ).html('Total');
           
            $( api.column( 3 ).footer() ).html(bulletTotal);
            $( api.column( 7 ).footer() ).html(leadTotal);
            $( api.column( 8 ).footer() ).html(cashTotal);
          
        },

Answers

  • kthorngrenkthorngren Posts: 21,468Questions: 26Answers: 4,977

    Use the number renderer the same as we discussed in your other thread.

    Kevin

  • martin1223345martin1223345 Posts: 84Questions: 23Answers: 0

    I tried. But i cant seem to get it done. I dont know where to place it. All places i tried where no succes..

  • martin1223345martin1223345 Posts: 84Questions: 23Answers: 0

    Tried it like this after some thinking about your answer. Also no succes. So what has to be rendererd?

    $( api.column( 8 ).footer() ).html($.fn.dataTable.render.number('.', '.', 0).display(cashTotal);
    
  • martin1223345martin1223345 Posts: 84Questions: 23Answers: 0

    Got it ! Thanks !

    The code:

           // Update footer by showing the total with the reference of the column index 
            $( api.column( 0 ).footer() ).html('Total');
               var numberRenderer = $.fn.dataTable.render.number('.', '.', 0).display;
                $( api.column( 3 ).footer() ).html(numberRenderer( bulletTotal ));
                $( api.column( 7 ).footer() ).html(numberRenderer( leadTotal ));
                $( api.column( 8 ).footer() ).html(numberRenderer( cashTotal ));
                
            
            },
    
This discussion has been closed.