преобразовать ячейки таблицы для формирования входного текста с помощью django

У меня есть html-таблица, отображаемая с помощью django-tables2, и мне нужно взять значение из трех столбцов fitt и передать его в качестве аргумента другому шаблону.

{% block table %}
 <table id="myTable" class="table table-striped table-hovered table-bordered table-condensed"{% 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 %}

        {% endfor %}
    </tbody>
    {% endblock table.tbody %}
    {% block table.tfoot %}
    <tfoot></tfoot>
    {% endblock table.tfoot %}
 </table>
 {% if table.page %}
 {% block pagination %}
   {% bootstrap_pagination table.page %}
 {% endblock pagination %}
{% endif %}
{% endblock table %}

Мне нужно взять значение из трех первых столбцов и передать его в качестве аргумента. В четвертом столбце у меня есть раскрывающаяся кнопка, вставленная с помощью функции javascript, я могу вставить входной текст с помощью функции JS, но я не знаю, как передать значение ячейки во входную ячейку. Если изменить эту строку

<td {{ column.attrs.td.as_html }}>{{ cell }}</td>

как это

<td {{ column.attrs.td.as_html }}><input type="text" value="{{ cell }}"</td>

Работает, но все ячейки преобразуются во входной текст, и мне нужно преобразовать только первые три столбца.


person Joseleg    schedule 28.10.2014    source источник


Ответы (1)


Ну можно попробовать так:

{% for row in table.page.object_list|default:table.rows %}
        {% block table.tbody.row %}
        <tr class="{% cycle 'odd' 'even' %}">
            {% for column, cell in row.items %}
                {% if forloop.counter < 4 %}
                   <td {{ column.attrs.td.as_html }}><input type="text" value="{{ cell }}"</td>

                {% else %}

                   <td {{ column.attrs.td.as_html }}>{{ cell }}</td>

                {% endif %}

            {% endfor %}
        </tr>
        {% endblock table.tbody.row %}

        {% endfor %}
person ruddra    schedule 30.10.2014