Formatting data in a coloumn
Formatting data in a coloumn
gunjannigam
Posts: 8Questions: 0Answers: 0
Hi,
I want to format the data in a column. It is in float format and I want to convert it to a integer. How is that possible??
I want to format the data in a column. It is in float format and I want to convert it to a integer. How is that possible??
This discussion has been closed.
Replies
you define it in aoColumns, or aoColumnDefs. see http://www.datatables.net/ref
fnRender gets passed one parameter oObj which has the row number, column number, array of row data, and the table settings "oSettings" object. return a string that represents that cell's rendered value.
oObj.iDataColumn
oObj.iDataRow
oObj.aData
oObj.oSettings
[code]
/* Using aoColumnDefs */
$(document).ready(function() {
$('#example').dataTable( {
"aoColumnDefs": [
{
"fnRender": function ( oObj ) {
var s = oObj.aData[iDataColumn]; // current value
if (isNaN(s)) return "0";
return parseInt(s).toString();
},
"aTargets": [ 0 ]
}
]
} );
} );
/* Using aoColumns */
$(document).ready(function() {
$('#example').dataTable( {
"aoColumns": [
{ "fnRender": function ( oObj ) {
var s = oObj.aData[iDataColumn]; // current value
if (isNaN(s)) return "0";
return parseInt(s).toString();
} },
null,
null,
null,
null
]
} );
} );
[/code]