<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|add:1 }} treegrid-parent-{{ forloop.counter }}">
<td>{{ product.title }}</td>
</tr>
{% endfor %}
{% endif %}
{% endfor %}
</table>
<table class="table">
{% for category in categorys %}
{% if category.is_leaf_node %}
<tr class="treegrid-{{ forloop.counter }}">
{% set outer_counter = forloop.counter %}
<td>{{ category.name }}</td>
</tr>
{% for product in category.get_products %}
<tr class="treegrid-{{ forloop.counter|add:1 }} treegrid-parent-{{ outer_counter }}">
<td>{{ product.title }}</td>
</tr>
{% endfor %}
{% endif %}
{% endfor %}
</table>