adding commas to unformatted numbers
adding commas to unformatted numbers
Hi Allan,
First, thanks for such a great product!! I hope this is a rather easy question. I have 9 columns in my table via server side processing. The last 6 i need % signs, and I figured that much out below. I'm having trouble with column 3 where I would need to add a comma to an unformatted number (e.g. 1000000 becomes 1,000,000) in the table. I searched for a similar example with fnRender but could not find.
[code]
"aoColumnDefs": [
{ "sClass": "center", "aTargets": [ 2,3,4,5,6,7,8 ] }
],
"aoColumns": [
null,
null,
{ "fnRender": function ( oObj ) {
return oObj.aData[2];
} },
{ "asSorting": [ "desc", "asc" ], "fnRender": function ( oObj ) {
return oObj.aData[3] +'%';
} },
{ "asSorting": [ "desc", "asc" ], "fnRender": function ( oObj ) {
return oObj.aData[4] +'%';
} },
{ "asSorting": [ "desc", "asc" ], "fnRender": function ( oObj ) {
return oObj.aData[5] +'%';
} },
{ "asSorting": [ "desc", "asc" ], "fnRender": function ( oObj ) {
return oObj.aData[6] +'%';
} },
{ "asSorting": [ "desc", "asc" ], "fnRender": function ( oObj ) {
return oObj.aData[7] +'%';
} },
{ "asSorting": [ "desc", "asc" ], "fnRender": function ( oObj ) {
return oObj.aData[8] +'%';
} }
]
[/code]
Thanks!
Patrick
First, thanks for such a great product!! I hope this is a rather easy question. I have 9 columns in my table via server side processing. The last 6 i need % signs, and I figured that much out below. I'm having trouble with column 3 where I would need to add a comma to an unformatted number (e.g. 1000000 becomes 1,000,000) in the table. I searched for a similar example with fnRender but could not find.
[code]
"aoColumnDefs": [
{ "sClass": "center", "aTargets": [ 2,3,4,5,6,7,8 ] }
],
"aoColumns": [
null,
null,
{ "fnRender": function ( oObj ) {
return oObj.aData[2];
} },
{ "asSorting": [ "desc", "asc" ], "fnRender": function ( oObj ) {
return oObj.aData[3] +'%';
} },
{ "asSorting": [ "desc", "asc" ], "fnRender": function ( oObj ) {
return oObj.aData[4] +'%';
} },
{ "asSorting": [ "desc", "asc" ], "fnRender": function ( oObj ) {
return oObj.aData[5] +'%';
} },
{ "asSorting": [ "desc", "asc" ], "fnRender": function ( oObj ) {
return oObj.aData[6] +'%';
} },
{ "asSorting": [ "desc", "asc" ], "fnRender": function ( oObj ) {
return oObj.aData[7] +'%';
} },
{ "asSorting": [ "desc", "asc" ], "fnRender": function ( oObj ) {
return oObj.aData[8] +'%';
} }
]
[/code]
Thanks!
Patrick
This discussion has been closed.
Replies
If you are using the 1.7 betas you can use the function oSettings.fnFormatNumber( {number} ) (or fnSettings.fnFormatNumber(...)) which will do exactly this task of splitting the number up for you. If this isn't quite suitable, or you are using 1.6.x, then you can simply pull that code out of 1.7 and use it as your own function :-)
Regards,
Allan
Thanks for the prompt reply. I must be doing something wrong in terms of syntax. I'm still having difficulty following your advice incorporating it into my code. Do I use the function within the "aoColumns": [ section?
Thanks for your patience!
Pat
Regards,
Allan
Thanks again for everything Allan!