2014-10-28 75 views
0

我有一個用django-tables2呈現的html表格,我需要從三個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 %} 
相關問題