【问题标题】:Split html table rows to another column将html表格行拆分到另一列
【发布时间】:2016-03-14 03:58:49
【问题描述】:

我想 for 循环我的数据以呈现表格

my datas = [[1, 'count'], [2, 'count'], [3, 'count'], ..., ['total', 'count']]

继续本月的日子

我想像这样将我的数据呈现到表格中 所以当 for 循环计数器到 9 时,它将创建/移动到另一列并继续渲染数据。

我试过这个,但它是水平的:

<table class="table table-bordered table-striped">
  <tr>
    {%for item in new_client_dict %}
    <td>{{ item.0 }}</td>
    <td>{{ item.1 }}</td>
    {%if forloop.counter|divisibleby:"9"%}
  </tr>
  <tr>
    {%endif%}
    {%endfor%}
  </tr>
</table>
有什么建议吗?谢谢

【问题讨论】:

    标签: python html django twitter-bootstrap


    【解决方案1】:

    尝试使用 divisible_by 关闭 &lt;tr&gt; 并打开一个新行。示例:

    <tr>
    {%for item in items%}
    <td>{{data}}</td>
    {%if forloop.counter|divisible_by:"9"%}
    </tr>
    <tr>
    {%endif%}
    {%endfor%}
    </tr>
    

    【讨论】:

      【解决方案2】:

      假设您不介意将它们放在单独的表中(并排在同一行中),您使用它数天(最多 = 31,4 列,9 行),并且您正在使用引导程序(如问题标签)你可以这样做:

      <div class='row'>
      
      
          {%for item in items%}
              {% if forloop.counter = "1" %} #I can't tell if this counter starts with 0 or one, be sure to make it the first interation number
                  <div class='col-lg-3'>
                  <table class="table table-bordered table-striped">
                  <tbody>
              {% endif %}
              {% if forloop.counter|divisible_by:"9" %}
                  </tbody>
                  </table>
                  </div>
                  <div class='col-lg-3'> # lg, sm, xl, choose your flavor
                  <table class="table table-bordered table-striped">
                   #add header here #
                  <tbody>
              {% endif %}
              <tr>
                  <td>{{ item.0 }}</td>
                  <td>{{ item.1 }}</td>
              </tr>
           {% endfor %}
                  </tbody>
                  </table>
                  </div>
      
      </div>
      

      【讨论】:

      • @vinCi 我很确定您可以调整 css(可能制作自己的分隔文件会更好)以实现您想要的。这段代码似乎适用于我的设置(python 2.7,django 1.9)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多