[Answer]-AngularJS – interactive table with Django

1👍

    <td>{% endverbatim %}{{ w.1}}{% verbatim %}{{-(val1 + val2 + val3 + val4 + val5 + val6) }}</td>
{% endverbatim %}

i think is something like this, becausew.1 is django template, should be out of verbatim

0👍

The reason your entries are being duplicated between lines is becuase they are all referencing the same ng-model. e.g. All of the entries in column 3 are attached to the val1 model. You have to either assign each item an individual model name, or use ng-repeat instead of django for loop to repeat your rows.

Perhaps this would give your desired result.

{% verbatim %}
    <td><input type="number" ng-model="{% endverbatim %}row_{{forloop.counter}}{% verbatim %}val1" /></td>
    <td><input type="number" ng-model="{% endverbatim %}row_{{forloop.counter}}{% verbatim %}val2" /></td>
    <td><input type="number" ng-model="{% endverbatim %}row_{{forloop.counter}}{% verbatim %}val3" /></td>
    <td><input type="number" ng-model="{% endverbatim %}row_{{forloop.counter}}{% verbatim %}val4" /></td>
    <td><input type="number" ng-model="{% endverbatim %}row_{{forloop.counter}}{% verbatim %}val5" /></td>
    <td><input type="number" ng-model="{% endverbatim %}row_{{forloop.counter}}{% verbatim %}val6" /></td>
    <td>{{ {% endverbatim %} w.1-(row_{{forloop.counter}}val1 + row_{{forloop.counter}}val2 + row_{{forloop.counter}}val3 + row_{{forloop.counter}}val4 + row_{{forloop.counter}}val5 + row_{{forloop.counter}}val6) {% verbatim %} }}</td>
{% endverbatim %}

I’m not sure how the mixing of verbatim and template tags will work, it’s probably best to handle the calculation in your angular controller anyway.

👤jef79m

Leave a comment