Django admin line conditional background color fill

Asked

Viewed 74 times

0

I am wanting to color an entire row of a table, if the respective column of that row has some text, there are three possible situations: 1. the text itself, 2. fields with a "-", 3. fields with nothing. The column referring to is 9, observation field, and tried as follows , without success:

(function($) {
$(document).ready(function() {
$('#result_list tr:nth-child(9)').each(function() {
if ($(this).text() != '-') {
  $(this).css({
      "background-color": 'yellow',
      "color" : "black"
  });
}
if ($(this).text() != '') {
 $(this).css({
     "background-color": 'yellow',
      "color" : "black"
  });
}

});
});
})(django.jQuery);

1 answer

0

Here’s what I just tested in the Django 2.0.x admin from the Chrome console.

Before, for every column of a field, Django adds a class in the format field-nomedocampo. This should render in html:

<td class="field-campo">texto</td>

So, given that, I believe that your jquery might be something like:

var $ = django.jQuery; // precisei disso para testar a solução
$('#result_list .field-SEU_CAMPO_AQUI').each(function() {
    if ($(this).text() == "-") {
        $(this).closest('tr').css("background-color", "red");
    }
});

I hope it will be useful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.