render footer callback as currency

render footer callback as currency

crush123crush123 Posts: 417Questions: 126Answers: 18
edited September 2015 in DataTables 1.10

Using the example https://datatables.net/examples/advanced_init/footer_callback.html

I have 2 columns displaying the total in the footer

a code snippet is as follows....

// Update footer
        $( api.column( 4 ).footer() ).html(
            'Due £'+ totaldue
        );
        $( api.column( 5 ).footer() ).html(
            'Paid £'+ totalpaid
        );  

Some values show a single digit after the decimal point 0- is it possible to render the callback values as currency ?

This question has an accepted answers - jump to answer

Answers

  • ThomDThomD Posts: 334Questions: 11Answers: 43
    Answer ✓

    Here is the function to format a number, including adding a currency label and decimal control.

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

    example is here

    https://editor.datatables.net/examples/simple/simple.html

  • crush123crush123 Posts: 417Questions: 126Answers: 18

    Awesome, thanks for your quick reply.

    Here is my updated snippet...

    // Update footer
            var numFormat = $.fn.dataTable.render.number( '\,', '.', 2, '£' ).display;
            $( api.column( 4 ).footer() ).html(
                'Due '+ numFormat(totaldue)
            );
            $( api.column( 5 ).footer() ).html(
                'Paid '+ numFormat(totalpaid)
            );      
    
This discussion has been closed.