Formatting data in a coloumn
Formatting data in a coloumn
![gunjannigam](https://secure.gravatar.com/avatar/f3f225dfcfdc855a0bbe9d828d8e877d/?default=https%3A%2F%2Fvanillicon.com%2Ff3f225dfcfdc855a0bbe9d828d8e877d_200.png&rating=g&size=120)
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]