angular-datatables
angular-datatables copied to clipboard
Cell background color by value
Thanks for this amazing plugin! , I have one question >> How I can color the background of a given cell? For Ex... If the value of a cell is greater than a certain threshold, i would like to apply a different bg color, only for the cell. Is it possible? How? Thanks!
I found solution by rendering the data of the cell with Html renderer
DTColumnBuilder.newColumn(price).withTitle("Price").notSortable().renderWith(priceRenderer())
function priceRenderer() {
return function(data, type, full, meta){
var highlightGr = data.price;
var returnClass = "";
highlightGr > 1 ? returnClass = "gr" : returnClass = "re";
return '<span class="'+returnClass+'">'+ data.price+' € </span>'
};
}
and after drawing the table :
var dtOfferOptions = DTOptionsBuilder.fromFnPromise(function() {return $q.when(vm.Data)})
.withOption('drawCallback', function(settings) {
angular.element(document).find('.gr').parent().addClass('green-td');
angular.element(document).find('.re').parent().addClass('red-td');
})
Where do I put the code in var dtOfferOptions ??
In your HTML code:
<table datatable dt-options="dtOfferOptions" dt-columns="dtColumns">