코딩

django template : forloop / parentloop / first를 이용한 표 만들기

Bullseye 불새 2022. 10. 17. 08:37
{% regroup column_list_bottom_left by 국내해외 as data0 %}
    {% for eachDom in data0 %}
        {% regroup eachDom.list by 본부 as data1 %}
            {% for eachBonbu in data1 %}
                {% regroup eachBonbu.list by 현장 as data2 %}
                    {% for eachSite in data2 %}
                        <!-- 각 줄별로-->
                        {% for rowData in eachSite.list %}
                            <tr>
                                {% if forloop.first %}
                                    {% if forloop.parentloop.first %}
                                        {% if forloop.parentloop.parentloop.first %}
                                            <td class="data" rowspan="{{eachDom.list|length}}"><div class="align-center ellipsis" style="width:100px;">{{eachDom.grouper}}</div></td>
                                        {% endif %}
                                        <td class="data" rowspan="{{eachBonbu.list|length}}"><div class="align-center ellipsis" style="width:100px;">{{eachBonbu.grouper}}</div></td>
                                    {% endif %}
                                <td class="data" rowspan="{{eachSite.list|length}}"><div class="align-center ellipsis" style="width:250px;">{{eachSite.grouper}}</div></td>
                                {% endif %}

                                <td class="data"><div class="align-center ellipsis" style="width:200px;">{{rowData.업체}}</div></td>
                                <td class="data"><div class="align-center ellipsis" style="width:100px;">{{rowData.입력일수}}</div></td>
                            </tr>
                        {% endfor %}
                    {% endfor %}
            {% endfor %}
    {% endfor %}

템플릿 코드만으로 HTML Table에서 하기와 같은 표를 만들 수 있음