P
P
Pan Propan2016-04-08 18:26:12
Django
Pan Propan, 2016-04-08 18:26:12

How to form bootstrap tree table?

To form a tree in Django, I use django-mptt, to display on the front, the Jquery-treegid library .
I displayed the tree itself, but I just can’t figure out how to attach JS to it.
037171805241471ca88263220d237da7.png
The code itself is below, I gave 3 options,
1) just a tree
2) my code
3) a test example that correctly processes JS


<ul>
        {% recursetree nodes %}
            <li>
                {{ node.name }}  {{ node.price }}
                {% if not node.is_child_node %}
                    <ul class="children">
                        {{ children }}
                    </ul>
                {% endif %}
            </li>
        {% endrecursetree %}
    </ul>



    <table class="table">
    {% recursetree nodes %}
        <tr class="treegrid-1">
            <td>{{ node.name }}</td><td>{{ node.price }}</td>
        </tr>

        {% if node.is_child_node %}
        <tr class="treegrid-parent-1">
            <td>{{ children }}</td>
        </tr>
        {% endif %}
    {% endrecursetree %}
    </table>



    <table class="table">
  <tr class="treegrid-1">
    <td>Root node</td><td>Additional info</td>
  </tr>
  <tr class="treegrid-2 treegrid-parent-1">
    <td>Node 1-1</td><td>Additional info</td>
  </tr>
  <tr class="treegrid-3 treegrid-parent-1">
    <td>Node 1-2</td><td>Additional info</td>
  </tr>
  <tr class="treegrid-4 treegrid-parent-3">
    <td>Node 1-2-1</td><td>Additional info</td>
  </tr>
    </table>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pan Propan, 2016-04-12
@mgis

<table class="table">
    {% for category in categorys %}
        {% if category.is_leaf_node %}
        <tr class="treegrid-{{ forloop.counter }}">
            <td>{{ category.name }}</td>
        </tr>
            {% for product in category.get_products %}
                <tr class="treegrid-{{ forloop.counter }} treegrid-parent-{{ forloop.counter }}">
                    <td>{{ product.title }}</td>
                </tr>
            {% endfor %}
        {% endif %}
    {% endfor %}
    </table>

Very close to the solution, it remains somehow to achieve getting the value forloop.counter + 1.
This is impossible in the template. =(

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question