Changing Column To "Price" (Value)

Changing Column To "Price" (Value)

qdataqdata Posts: 24Questions: 0Answers: 0
edited August 2011 in General
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!

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    fnRender lets you customize the rendering of a column.

    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]
  • qdataqdata Posts: 24Questions: 0Answers: 0
    In what file do I make changes in?
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    wherever your $('#example').dataTable() initialization is
  • qdataqdata Posts: 24Questions: 0Answers: 0
    I am getting an error...

    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 ]
    }
    ]
    } );
    } );
  • qdataqdata Posts: 24Questions: 0Answers: 0
    The items in the column are showing up as "Undefined"

    The error is as follows:

    "DataTables warning(table id = 'example'): Requested unknown parameter '3' from the dataa source for row 0"
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    fnRender is already a function, so you can just put your code right inside it

    [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]
  • qdataqdata Posts: 24Questions: 0Answers: 0
    The following is not working and the rendering has now lost the entire styling and is just raw text:


    $(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 ]
    } ]
    } );
    } );
This discussion has been closed.