A Django widget for use with a ModelMultipleChoiceField to allow easy jQuery DataTables sorting and pagination by rendering the selector as a table.
pip install django-table-select-widgetExample 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,
datatable_options={'language': {'url': '/foobar.js'}},
),
)Render it normally with a Django form.
Default: False
If True, it inserts JavaScripts, that enables shift-selection of multiple checkboxes. JQuery is required to be activated for this feature.
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>Default: False
If True, it inserts BootStrap classes to the table.
Default: {}
Dictionary with additional parameters which will be passed to DataTable initialization.
These options will get formated by json.dumps, so it can contain more complex structures.
Default parameter values set by DjangoTableSelectMultipleWidget can be overriden by this parameter.
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
