2014-10-28 1 views
0

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

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

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

ответ

0

Ну вы можете попробовать, как это:

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