Reputation: 32321
How to change the background color or a Table cell depending on other column value in Jquery Datatable ??
In this fiddle http://jsfiddle.net/5fbo72rm/4/
The table has got three coulmns Name ,Price and Quantity .
How can i change the background color of that Name cell if the quantity is greater than 40000
<table id="allwl">
<th class="hidden-480">Price</th>
<th class="hidden-480">Volume</th>
<th class="hidden-480">Quantity</th>
</table>
var dataSet = [
[
"1441.75",
"100"],
[
"1614.45",
"50"
],
[
"834.15",
"3000"]
];
var array_names = ["APPLE", "WHIRLPOOL", "SAMSUNG"];
for (var key in dataSet) {
if (dataSet.hasOwnProperty(key)) {
dataSet[key].splice(0, 0, array_names[key]);
}
}
$(function () {
$('#allwl').dataTable({
"iDisplayLength": -1,
"data": dataSet,
"columns": [{
"title": "Name"
}, {
"title": "Price"
}, {
"title": "Quantity"
}]
});
})
I have tried with createdcell , but that is only working with that particuarlar cell ,not for other cell
Could anybody please help me ,how to resolve this ??
http://jsfiddle.net/5fbo72rm/6/
Upvotes: 0
Views: 3384
Reputation: 339
$(document).ready(function(){
$('#allwl tr').each(function() {
var abc = $(this).children('td').eq(2).html();
if(!abc) {
return false;
}
else {
if(abc > 40000) {
$(this).children('td').eq(0).css('background-color', 'red');
}
}
});
});
here is your jsfiddle http://jsfiddle.net/sjkurani/5fbo72rm/9/
Upvotes: 1