I want to have sortable columns in my tables (just like what is done for the admin changelists)....I'm looking for a solution that will be easy to implement and customize if I want.
How can I do this?
I want to have sortable columns in my tables (just like what is done for the admin changelists)....I'm looking for a solution that will be easy to implement and customize if I want.
How can I do this?
Javascript? There are plenty of table sorters out there:
If you use pagination than a Javascript table sorter might not be sufficient or behave unexpected.
Create every column header as a link e.g.
<th><a href="?order_by=name">Name</a></th>
and in your view you check whether the order_by
parameter is set or not:
order_by = request.GET.get('order_by', 'defaultOrderField');
Model.objects.all().order_by(order_by)