I can send my model to the html
page and bring it to the array structure, but I cannot integrate this array
into the grid table. Does anyone know how I can do this?
views.py
def tests(request):
resultQueryet = ResultsModel.objects.all()
requests = serialize('json', resultQueryet)
context = {
"requests" : requests
}
return render(request, 'admin/tests.html', context=context)
html
{% block content %}
<div class="card-body">
<div id="table-card" class="table-card"></div>
</div>
{% endblock %}
{% block extra_js %}
<script>
var model = {{requests|safe}};
console.log(model)
document.getElementById("table-card") &&
new gridjs.Grid({
columns: ["Name", "Surname", "Date", "Amount", "Result", "Details"],
sort: !0,
pagination: { limit: 5 },
data: [
[
{% for x in model %}
{{x.name}},
{{x.surname}},
{{x.date}},
{{x.amount}},
{{x.result}},
{{x.details}},
{% endfor %}
],
],
}).render(document.getElementById("table-card"))
</script>
<script src="{% static 'libs/prismjs/prism.js'%}"></script>
<script src="{% static 'libs/gridjs/dist/gridjs.umd.js'%}"></script>
<script src="{% static 'js/pages/gridjs.init.js'%}"></script>
{% endblock extra_js %}
I can view the model as array
on the console
screen, but I cannot print it to the table via a for loop
.