-
Define form class inherited from
BaseFilterForm
class TableFilterForm(BaseFilterForm): FIELDS = OrderedDict([ ('', ''), ('title', _('Title')), ('type', _('Course Type')), ])
-
Add to
views.py
and overrideget_filtered_data
methodclass TableListView(FilterMixin, ListView): template_name = 'table_list.html' form_class = TableFilterForm def get_filtered_data(self, object_list): return [{ '': '', 'title': obj.title, 'course_type': obj.get_course_type_display().title(), } for obj in object_list]
-
In template add js
jquery.dataTables.min.js
,dataTables.responsive.min.js
and cssjquery.dataTables.min.css
,responsive.dataTables.min.css
-
Setup DataTable
$('table').DataTable( { "scrollCollapse": true, "bLengthChange": false, "scrollY": true, "scrollX": false, "processing": true, "serverSide": true, "columns": [ {"data": "", 'searchable': false, 'orderable': false, "className": "control"}, {"data": "title"}, {"data": "type"} ], fnServerParams: function ( aoData ) { if (aoData.order.length) { aoData.sort_column = aoData.order[0]['column']; aoData.sort_asc = aoData.order[0]['dir'] === 'asc' ? '' : '-'; } }, responsive: { details: { type: 'column' } } });
-
Notifications
You must be signed in to change notification settings - Fork 0
anndoc/django-datatable-snippet
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
django snippet for JQuery DataTable plugin
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published