Changing Column To "Price" (Value)
Changing Column To "Price" (Value)
I am looking to change the 4th Column (Engine Version) to "Price" where all items in that column should be formatted as US currency with zero decimal places (Excel language = format to Currency category, Zero decimal places, Symbol ="$").
Any help would be appreciated!
Any help would be appreciated!
This discussion has been closed.
Replies
http://www.datatables.net/ref#fnRender
http://datatables.net/examples/advanced_init/column_render.html
[code]
$(document).ready(function() {
$('#example').dataTable( {
"aoColumnDefs": [
{
"fnRender": function ( oObj ) {
// oObj has .iDataRow, .iDataColumn, .aData, and .oSettings
val = oObj.aData[oObj.iDataColumn];
// now convert your val into your desired format
// ...
},
"aTargets": [ 3 ]
}
]
} );
} );
[/code]
Here is what I have so far...
$(document).ready(function() {
$('#example').dataTable( {
"aoColumnDefs": [
{
"fnRender": function ( oObj ) {
// oObj has .iDataRow, .iDataColumn, .aData, and .oSettings
val = oObj.aData[oObj.iDataColumn];
function CurrencyFormatted(amount)
{
var i = parseFloat(amount);
if(isNaN(i)) { i = 0.00; }
var minus = '';
if(i < 0) { minus = '-'; }
i = Math.abs(i);
i = parseInt((i + .005) * 100);
i = i / 100;
s = new String(i);
if(s.indexOf('.') < 0) { s += '.00'; }
if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
s = minus + s;
return s;
}},
"aTargets": [ 3 ]
}
]
} );
} );
The error is as follows:
"DataTables warning(table id = 'example'): Requested unknown parameter '3' from the dataa source for row 0"
[code]
$(document).ready(function() {
$('#example').dataTable( {
"aoColumnDefs":
[ {
"fnRender": function ( oObj ) {
// oObj has .iDataRow, .iDataColumn, .aData, and .oSettings
amount = oObj.aData[oObj.iDataColumn];
var i = parseFloat(amount);
if(isNaN(i)) { i = 0.00; }
var minus = '';
if(i < 0) { minus = '-'; }
i = Math.abs(i);
i = parseInt((i + .005) * 100);
i = i / 100;
s = new String(i);
if(s.indexOf('.') < 0) { s += '.00'; }
if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
s = minus + s;
return s;
}},
"aTargets": [ 3 ]
} ]
} );
} );
[/code]
$(document).ready(function() {
oTable = $('#example').dataTable({
"aoColumnDefs":
[ {
"fnRender": function ( oObj ) {
// oObj has .iDataRow, .iDataColumn, .aData, and .oSettings
amount = oObj.aData[oObj.iDataColumn];
var i = parseFloat(amount);
if(isNaN(i)) { i = 0.00; }
var minus = '';
if(i < 0) { minus = '-'; }
i = Math.abs(i);
i = parseInt((i + .005) * 100);
i = i / 100;
s = new String(i);
if(s.indexOf('.') < 0) { s += '.00'; }
if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
s = minus + s;
return s;
}},
"aTargets": [ 3 ]
} ]
} );
} );