/ / converte células da tabela para formar texto de entrada com django - javascript, django, django-forms, django-tables2

converta células de tabela para formar texto de entrada com django-javascript, django, django-forms, django-tables2

Eu tenho uma tabela html renderizada com django-tables2 e preciso pegar o valor das três primeiras colunas e passá-lo como argumento para outro modelo.

{% 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 %}

Eu preciso pegar o valor dos três primeiroscolunas e passe-o como argumento. Na quarta coluna, tenho um botão suspenso inserido com uma função javascript, posso inserir o texto de entrada com uma função JS, mas não sei como passar o valor da célula para a célula de entrada. Se mudar esta linha

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

como isso

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

Funciona, mas todas as células são convertidas em texto de entrada e eu só preciso converter as três primeiras colunas

Respostas:

0 para resposta № 1

Bem, você pode tentar assim:

{% 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 %}