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?
If you use pagination rather than a Javascript table sorter, it 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With