put data money + quantity together
put data money + quantity together
in have this:
column [
{ data: "incomes.revenue" , render: $.fn.dataTable.render.number( ',', '.', 2, '$' ) },
]
So in the cell i get i.ex: 1,234.98$
i have now a data:"incomes.money", it can be $ or €
what i need is something like:
column [
{ data: "incomes.revenue" , render: $.fn.dataTable.render.number( ',', '.', 2, 'incomes.money' ) },
]
could it be possible?
i end up with that, but i lose the thousand separator also de inline edit property i have.
{ data: null, render: function ( data, type, row ) {
return data.incomes.money + '' +data.incomes.revenue;
} },
any solutions please
This question has an accepted answers - jump to answer
Answers
Not sure whether I understand what you want to achieve but I think something is wrong with your code. I guess you would need to replace
with
Please see: https://datatables.net/reference/option/columns.render
If you are using PHP at the back end you could do the rendering there as well. I use Editor there as well. This is my getFormatter for amounts.
called here:
Hi biluses, my money formatting requirements are not as complex as yours, but most of my applications deal with currency. I don't know if this will help you, but I found this tiny library extremely useful for formatting money, easy to use, and well documented.
http://openexchangerates.github.io/accounting.js/
Yes, you can do what you are looking for on the client-side:
then use
columns.render
as a function:This basically makes use of the fact that we can save functions into variables in Javascript. In this case we are saving the display rendering function from the number formatter (very functional... ).
Allan
So,
incomes.money
contains your currency symbol andincomes.revenue
the value?Try something like this:
Basically,
$.fn.dataTable.render.number(...)
returns a function (in a closure) that takes (data, type, row) parameters that then gets executed immediately with your row (that now has access to the rest of the row data because we implement a render function (the outer function). It's a bit dirty since it calls$.fn.dataTable.render.number(...)
EVERY time it's called instead of once at initialisation time@allan: Your solution is something you should put into the docs! I wasn't smart enough to figure this out. That's why I am doing all of this stuff with PHP at the back end.
@allan thank you as allways that was great! working perfectly!