Formating a rendered number of a column
Formating a rendered number of a column
            
                            
                                  in DataTables 2             
        Hello,
I have a number column that I am rendering that way:
{data: "reporting_header.balance_CLBD_amount_amount", render: DataTable.render.number(null, null, 2), className: 'dt-body-right' }
But I must add a condition statement which calculate the value of the column:
{data: null, render: function ( data, type, row ) {
     if (data.reporting_header.balance_CLBD_credit_debit_indicator === 'DBIT') {
          return -1 * data.reporting_header.balance_CLBD_amount_amount;
     } else {
          return data.reporting_header.balance_CLBD_amount_amount;
     }
}}
How can I add to the second code the formating of the first?
This question has an accepted answers - jump to answer
Answers
You can either use Javascript toFixed() or chain
.display( .... )to the number renderer like this:AFAIK the
.display( ... )method is undocumented. I remember it from an old thread.Kevin
It is yes. The number renderer is handy for dealing with multi-locale tables (i.e. displaying in the locale format that the end user would expect), but if you just want some simple formatting like fix precision, then
toFixed()would be the way to do it.Allan
Dear both,
thanks for your prompt reply. I applied it that way and it looks like it worked like a charm: