Render number on computed value
Render number on computed value

Simple question:
I see how you use the formatters such as
columns:[
{
data: 'valueA', render: $.fn.dataTable.render.number(',', '.', 0, '$');
}
}
]
However, I am trying to use it on a computed number. Its easy enough to do this but I was wondering if there is a way to actually leverage what is already there. Something like
columns:[
{
data: null, render: function(rowData){
var sum = rowData.valueA + rowData.valueB;
return $.fn.dataTable.render.number(',', '.', 0, '$', sum);
}
}
]
Scott
This discussion has been closed.
Replies
Hi Scott,
is what you want.
The
$.fn.dataTable.render.number()
call returns an object which DataTables can then use for the orthogonal data calls. Thedisplay
property of that object is the function that will do the display aspect. Source code for it is here.Allan
Hi Allen,
I'm using this to render currency column in a datatable (nightly build) as follows
{data: 'real_current_value', name: 'real_current_value', render: $.fn.dataTable.render.number( ',', '.', 2, '$' )}
But whenever there is a value of zero in the database it renders a
$NaN.N
. I was originally using version 1.10.9 but changed to the nightly build as I saw this as a potential solution in another post here, but it made no difference (other than alt-row highlighting).I have to show correctly-formatted currency, but can't show the NaN for zeros. Without the render option, numbers, including zeros, display fine (just plain).
It would seem that the rendering function is the issue. How can I fix or workaround this?
Thanks in advance.
Hi @hondaman900 ,
It looks like you posted this comment on two threads. I replied on the other,
Cheers,
Colin