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

[Question] is there a way to change to color of a row?

Open p-rez opened this issue 10 years ago • 1 comments

Good evening! Sorry, me again. My question is simple i want to know if there's a way to change the color of a row by doing a condition.

for example i have my data as the image below: datarow Is there a way i could use the "bad_provider" element to do a condition and if it turns out to be true i could change the row color to red?

I have seen the documentation of datatables and it seems that i could do that from the createdRow method:

function createdRow(row, data, dataIndex) {
        // Recompiling so we can bind Angular directive to the DT

        $compile(angular.element(row).contents())($scope);
}

But i don't know how to do the condition and change the row color, is there a way to do it? or am i even approaching to this problem correctly? Thanks for your attention

p-rez avatar Jul 05 '16 20:07 p-rez

Nevermind i founded the solution by myself:

function createdRow(row, data, dataIndex) {
        // Recompiling so we can bind Angular directive to the DT
        if(data.bad_provider === true){
            $('td', row).addClass('danger');
        }
        $compile(angular.element(row).contents())($scope);
}

Inside createdRow function just add the condition you want to make and then the changes in it, pretty simple. If you want a specific colour it could be like this:

$('td', row).addClass('background-color', 'blue');

p-rez avatar Jul 05 '16 21:07 p-rez