angular-datatables icon indicating copy to clipboard operation
angular-datatables copied to clipboard

Cell background color by value

Open FadiNouh1 opened this issue 9 years ago • 3 comments

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!

FadiNouh1 avatar Apr 25 '17 19:04 FadiNouh1

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+' &euro; </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');
              })

FadiNouh1 avatar Apr 26 '17 14:04 FadiNouh1

Where do I put the code in var dtOfferOptions ??

posingh avatar Jul 20 '17 14:07 posingh

In your HTML code:

<table datatable dt-options="dtOfferOptions" dt-columns="dtColumns">

l-lin avatar Jul 21 '17 08:07 l-lin