adding commas to unformatted numbers

adding commas to unformatted numbers

patrickpatrick Posts: 3Questions: 0Answers: 0
edited July 2010 in General
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

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Patrick,

    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
  • patrickpatrick Posts: 3Questions: 0Answers: 0
    Hi 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
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Yes, use the rendering function inside your fnRender function. Just pass in your variable and out should pop a formatted string.

    Regards,
    Allan
  • patrickpatrick Posts: 3Questions: 0Answers: 0
    Awesome - got it!

    Thanks again for everything Allan!
This discussion has been closed.