How to sum cells then apply number format?

How to sum cells then apply number format?

monkeyboymonkeyboy Posts: 60Questions: 19Answers: 0

I am adding up some cells to get a row total. I do understand how to combine your render.number to that result:

columns: [
    { data: "myTable.Some Money",   "sClass": "binCentered",
            render: $.fn.dataTable.render.number( ",", ".", 0, "$" )
        },
        {
            data: null,
            className: "sum",
            render: function(data, type, row) {
            return parseInt(data.myTable.jan) + parseInt(data.myTable.feb) + parseInt(data.myTable.mar)
                + parseInt(data.myTable.apr) + parseInt(data.myTable.may) + parseInt(data.myTable.jun)
                + parseInt(data.myTable.jul) + parseInt(data.myTable.aug) + parseInt(data.myTable.sep)
                + parseInt(data.myTable.oct) + parseInt(data.myTable.nov) + parseInt(data.myTable.december);
            }
        },
        
        .
        .
        .
        .
    ]

As you can see I user number.render to format money with a dollar sign, and commas.
How can in include this withing my render function which sums my monthly cash?

Thanks for the help!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin
    Answer ✓

    Do this:

    var renderer = $.fn.dataTable.render.number( ",", ".", 0, "$" ).display;
    
    return renderer( sum );
    

    where sum is the summation value.

    Allan

  • monkeyboymonkeyboy Posts: 60Questions: 19Answers: 0

    Alan,

    As always - you ROCK!

This discussion has been closed.