How to use datatables with Twig (Symfony2)
How to use datatables with Twig (Symfony2)
Hi!
I am trying to use DataTables. I include the needed libraries (jquery.dataTables.css/dataTables.bootstrap.css & jquery.min.js/jquery.dataTables.min.js). I am using a target.html.twig. It works perfectly when my table is entirely written in HTML. But I am generating my table inside a twig template like this:
<table id="table_id" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Date d'ajout</th>
<th>Enregistré par</th>
<th>Deadline</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for courrier in listCourrier %}
<tr>
<td>{{ courrier.DateRegister().Creation()|date('d/m/y') }}</td>
<td>{{ courrier.User().Username() }}</td>
{% if courrier.Deadline() is null %}
<td>Aucune</td>
{% else %}
<td>{{ courrier.Deadline()|date('d/m/y') }}</td>
{% endif %}
<td align="center">
<a class="btn btn-default" href="{{ url('oc_courrier_ViewCourrierToConfirm', {'id': courrier.Id()}) }}"><em class="fa fa-pencil"></em></a>
<a class="btn btn-danger" href="{{ url('oc_courrier_delete', {'id': courrier.Id()}) }}"><em class="fa fa-trash"></em></a>
</td>
<tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<th>Date d'ajout</th>
<th>Enregistré par</th>
<th>Deadline</th>
<th>Actions</th>
</tr>
</tfoot>
</table>
My problem is that the arrows for sorting do not appear and the sorting function does not work. It works only if I write the whole
in HTML like in the examples from datatables.net.
Any ideas?