[Fixed]-Reuse javascript function for bootstrap tables in Django

1👍

Just reuse the template logic to your javascript. Something like this if I’ve figured it out correctly:

$(function () {
  {% for helis in helis_by_mnfcr %}
    {% if helis %}
      {% with id=helis_by_mnfcr.mnfcr.split|join:"_" %}
      var table_id = '#table_{{ id }}';
        $(table_id).bootstrapTable({
          data: data_{{ id }},
          striped: true,
          pagination: true,
          // ... Other attrs ommited
        });
      {% endwith %}
    {% endif %}
  {% endfor %}
});

So the above will create N bootstrapTables with the correct id and data (through the for loop).

Leave a comment