text color changes on based of different conditions
text color changes on based of different conditions
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?
This discussion has been closed.
Replies
[code]
"aoColumnDefs": [
{
"aTargets":[1],
"fnCreatedCell": function(nTd, sData, oData, iRow, iCol)
{
if(sData < 0) {
$(nTd).css('color', 'red');
}
}
}
]
[/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,
});
});