text color changes on based of different conditions

text color changes on based of different conditions

ilemenilemen Posts: 2Questions: 0Answers: 0
edited December 2012 in General
I am new to datatables and want to add a functionality in my datatable grid,all i m using in my project is java /jquery for functionality thus i want the negative data displayed in my datatable row should appear in red color.can someone help me on dis?and provide me an example for this?

Replies

  • girishmrgirishmr Posts: 137Questions: 0Answers: 0
    Here you go...

    [code]
    "aoColumnDefs": [
    {
    "aTargets":[1],
    "fnCreatedCell": function(nTd, sData, oData, iRow, iCol)
    {
    if(sData < 0) {
    $(nTd).css('color', 'red');
    }
    }
    }
    ]

    [/code]
  • ilemenilemen Posts: 2Questions: 0Answers: 0
    hey i m storing my data in an array and so i add the code as you directed bt it is still not working.Please check the below code
    $(document).ready(function(){
    var aaData=[
    {"Employee":9,"Transaction":4,"Amount":9},

    {"Employee":9,"Transaction":4,"Amount":-4},
    ];

    oTable = $('#example').dataTable({
    "aaData":aaData,

    "aoColumns":[
    {"mDataProp":"Employee","sTitle":"Employee","bSortable": false},
    {"mDataProp":"Transaction","sTitle":"Transaction","bSortable": true},
    {"mDataProp":"Amount","sTitle":"Amount","bSortable": true}
    ],
    "aoColumnDefs": [
    {
    "aTargets":[1],
    "fnCreatedCell": function(nTd, aaData, oTable, iRow, iCol)
    {
    if(aaData < 2) {
    $(nTd).css('color', 'red');
    }
    }
    }
    ],



    "bFilter": true,
    "bSortClasses":false,
    "sScrollX": "100%",
    "bScrollCollapse": true,
    "bSort": true,





    });



    });
  • girishmrgirishmr Posts: 137Questions: 0Answers: 0
    Are you targeting the correct column? Check your column index.
This discussion has been closed.