DjangoTableSelectMultipleWidget
A Django widget for use with a ModelMultipleChoiceField to allow easy jQuery DataTables sorting and pagination by rendering the selector as a table.
Installation
pip install django-table-select-widget
Example form field:
from table_select_widget import TableSelectMultiple
items = forms.ModelMultipleChoiceField(
queryset=myqueryset,
widget=TableSelectMultiple(
item_attrs=[
'tablecolumn1',
('tablecolumn2', "Table coulmn 2 header"),
'same__related__parameter',
],
enable_shift_select=True,
enable_datatables=True,
bootstrap_style=True,
),
)
Render it normally with a Django form.
Parameters
enable_shift_select
Default: False
If True
, it inserts JavaScripts, that enables shift-selection of multiple checkboxes. JQuery is required to be activated for this feature.
enable_datatables
Default: False
If True
, it inserts JavaScripts, that enables DataTables for the select table. JQuery and DataTables is required to be activated for this feature:
<script src="https://cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.7/css/jquery.dataTables.css"></link>
</script>
bootstrap_style
Default: False
If True
, it inserts BootStrap classes to the table.
Origin
Modified from https://djangosnippets.org/snippets/518/ for use with Python 3, Django 1.7.
Very similar to my TableSelect widget found here: https://github.com/willardmr/DjangoTableSelectWidget