Skip to content

willardmr/DjangoTableSelectWidget

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

DjangoTableSelectWidget

A Django widget for use with a ModelChoiceField to allow easy jQuery DataTables sorting and pagination by rendering the selector as a table.

Example form field:

items = forms.ModelChoiceField(
        queryset=myqueryset, widget=widgets.TableSelect(
        item_attrs=['tablecolumn1', 'tablecolumn2']))

Render it normally with a Django form.

Recommended Datatables Javascript to disallow sorting on the checkbox column:

<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>
$(document).ready(function(){
    $('#items').DataTable({
        "order": [],
        "columnDefs": [{
        "targets"  : 'no-sort',
        "orderable" : false,
    }]
    });
});
</script>

Modified from https://djangosnippets.org/snippets/518/ for use with Python 3, Django 1.7.

Very similar to my TableSelectMultiple widget found here: https://github.com/willardmr/DjangoTableSelectMultipleWidget

About

A Django widget for use with a ModelChoiceField to allow easy jQuery DataTables sorting and pagination.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages