Formatted numbers question

Formatted numbers question

brcambbrcamb Posts: 1Questions: 0Answers: 0
edited June 2013 in Plug-ins
I'd like to add some commas to some big numbers in my table. I've added the plug-in and the sType to my aoColumns with no luck. What am I missing? Any help would be appreciated. Thanks.

Here is my code:

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"formatted-num-pre": function ( a ) {
a = (a === "-" || a === "") ? 0 : a.replace( /[^\d\-\.]/g, "" );
return parseFloat( a );
},

"formatted-num-asc": function ( a, b ) {
return a - b;
},

"formatted-num-desc": function ( a, b ) {
return b - a;
}
} );

$(document).ready(function () {

$('#pension').dataTable({

"aaSorting": [[ 4, "desc" ]],
"bLengthChange": true,
"bInfo": true,
"aoColumns": [null, {"sClass": "center"}, null, {"sType":"formatted-num"}, {"sType":"formatted-num", "sClass": "left"}, { "bSearchable": true, "bVisible": false }, null]

});

});

here is a fiddle: http://jsfiddle.net/brcamb/wzW7L/11/

Replies

  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    The formatted numbers plug-in will sort numbers which are formatted. It will not add formatting to the numbers!

    How is your table generated? In php there are formatting number functions you could use, and other languages will have similar methods.

    The other option is to use mRender in DataTables and add a formatting function.

    Allan
This discussion has been closed.