Datatables Pagination Does Not Show
Solution 1:
You may well have tried some or all of these, but here are some thoughts which may help:
Make sure you're not using any configuration from the legacy version of datatables. You are using 1.10+ - so make sure that you use the correct v1.10 config.
Get it working without any Django tags first - just a standalone page. Then integrate the tags in stages so that you check it still works.
You can start with this example - get this working first and then add in the correct options as you need them.
Make sure you take some time to read the documentation - the datatables documentation is really good, and spending a bit of time on reading and understanding it will save a lot of time in the long run.
Also, try declaring your css / js imports in the HTML .
To start - just remove all the options and use the defaults:
$('#example').DataTable( {
} );
Once it's working, then make sure you add the correct options one at a time.
Solution 2:
Try this :
<script>// Call the dataTables jQuery plugin
$(document).ready(function() {
$('#mainTable').DataTable({
dom: 'Bfrtip',
buttons: [
'excel', 'pdf'
]
});
});
</script>
Solution 3:
I found an example online that I copied that finally worked. Here is a YT video that shows the example and has github repo to copy the code.
Below is the code from the github repo and the key part for me was wrapping the js code in the child template and then calling the code again via the same block in the base.html
This took me so long to figure out as I did not know the scripts were not being called. Feel free to leave a comment below to let me know the best way to figure out if a library script is being called.
{% block js %}
{% endblock js %}
and then also calling that in
base.html
...
<footer><p><h6> This site is brought to you by Python, Django and the YogiCoder</h6></p><h6><p>Contact information: <ahref="mailto:imtheyogicoder@gmail.com">imtheyogicoder@gmail.com</a></p></h6></footer></div>
{% block js %}
{% endblock js %}
</body></html>
child.html
....
{% block js %}
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><linktype="text/css"href="https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.10.18/af-2.3.0/b-1.5.2/b-colvis-1.5.2/b-flash-1.5.2/b-html5-1.5.2/b-print-1.5.2/cr-1.5.0/fh-3.1.4/r-2.2.2/datatables.min.css"/><scripttype="text/javascript"src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script><scripttype="text/javascript"src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script><scripttype="text/javascript"src="https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.10.18/af-2.3.0/b-1.5.2/b-colvis-1.5.2/b-flash-1.5.2/b-html5-1.5.2/b-print-1.5.2/cr-1.5.0/fh-3.1.4/r-2.2.2/datatables.min.js"></script><script>
$(document).ready( function () {
$('#table_id').DataTable({
dom: 'B<"clear">lfrtip',
buttons: {
name: 'primary',
buttons: [ 'copy', 'csv', 'excel', 'pdf' ]
}}
);
} );
</script></div>
{% endblock %}
Post a Comment for "Datatables Pagination Does Not Show"