[Django] django + able is simple to use in tables, djangodatatable
To use datatable, you must first download the datatable file. The file mainly includes three folders: css, img, and js. how to configure them in django?
First, you must introduce the datatable file in the template in the following format:
<!-- DataTables CSS --> <link rel="stylesheet" href="{% static 'DataTables/css/jquery.dataTables.css' %}"> <!-- jquery --> <script src="{% static 'js/jquery/jquery.min.js' %}"></script> <!-- DataTables --> <script src="{% static 'DataTables/js/jquery.dataTables.js' %}"></script>
Note that the js file in datatables must be referenced after the jquery file.
In django, how does one make data use the Ables table?
The Code is as follows:
<table id="table_id" class="display"> <thead> <tr> <th>Column 1</th> <th>Column 2</th> </tr> </thead> <tbody> {% for d in data %} <tr> <td>{{ d.col1 }}</td> <td>{{ d.col2 }}</td> </tr> {% endfor %} </tbody> </table><script>
$(document).ready( function () {
$('#table_id').DataTable();
} );
</Script>
Finished!