Formatted numbers question
Formatted numbers question
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/
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/
This discussion has been closed.
Replies
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