Formatting data in a coloumn

Formatting data in a coloumn

gunjannigamgunjannigam Posts: 8Questions: 0Answers: 0
edited August 2011 in General
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??

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    fnRender is probably ideal for that. fnRender is a function run on cells in a column to reformat or custom display them.

    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]
This discussion has been closed.