【发布时间】:2014-10-15 09:19:32
【问题描述】:
我想根据值动态更改单元格的背景颜色。 我使用 django-tables2 渲染我的表格并且工作正常。 这是我在模板中呈现表格的代码:
{% load querystring from django_tables2 %}
{% load trans blocktrans from i18n %}
{% load bootstrap_toolkit %}
{% if table.page %}
<div class="table-container">
{% endif %}
{% block table %}
<table class="table table-compact table-bordered"{% if table.attrs %} {{ table.attrs.as_html }}{% endif %}>
{% block table.thead %}
<thead>
<tr>
{% for column in table.columns %}
{% if column.orderable %}
<th {{ column.attrs.th.as_html }}><a href="{% querystring table.prefixed_order_by_field=column.order_by_alias.next %}">{{ column.header }}</a></th>
{% else %}
<th {{ column.attrs.th.as_html }}>{{ column.header }}</th>
{% endif %}
{% endfor %}
</tr>
</thead>
{% endblock table.thead %}
{% block table.tbody %}
<tbody>
{% for row in table.page.object_list|default:table.rows %} {# support pagination #}
{% block table.tbody.row %}
<tr class="{% cycle "odd" "even" %}">
{% for column, cell in row.items %}
<td {{ column.attrs.td.as_html }}>{{ cell }}</td>
{% endfor %}
</tr>
{% endblock table.tbody.row %}
{% empty %}
{% if table.empty_text %}
{% block table.tbody.empty_text %}
<tr><td colspan="{{ table.columns|length }}">{{ table.empty_text }}</td></tr>
{% endblock table.tbody.empty_text %}
{% endif %}
{% endfor %}
</tbody>
{% endblock table.tbody %}
{% block table.tfoot %}
<tfoot></tfoot>
{% endblock table.tfoot %}
</table>
{% endblock table %}
</div>
{% if table.page %}
{% block pagination %}
{{ table.page|pagination }}
{% endblock pagination %}
{% endif %}
我怀疑 django-tables2 或 Django 是否有一些属性来评估单元格的值,或者我需要创建一个 JavaScript 函数。 请给我一些链接或sn-p来实现这个功能
提前致谢
【问题讨论】:
-
您寻找的价值是否会经常变化,或者您寻找的价值是否相同? {% if %} 会起作用吗?
-
值不断变化,我尝试使用 {% if %} 但收到错误:无法解析剩余部分 '% If cell.e_reception == 2 %'。我会搜索这个错误。如果我找到什么我会让你知道的。感谢回复
标签: javascript ajax django html-table django-tables2