Datatables is a Django app that which gives the possibility to create views that integrates with the jQuery javascript library DataTables.
It also includes some features which makes it possible to export data to a csv from the table.
Add 'datatables'
to your INSTALLED_APPS
setting like this:
INSTALLED_APPS = [
...
'datatables',
]
- Create a view:
from datatables.views import DatatableView
from someapp.models import MyModel
class ExampleView(DatatableView):
model = MyModel
columns = [
'field1',
'field2',
'custom_data',
]
def custom_data(self, obj):
return 'some custom data'
- Add css and js to template:
example.html
{% load datatables %}
<html>
<head>
{% css_bundle %}
</head>
<body>
{{ datatable }}
</body>
{% js_bundle %}
</html>