Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sortable table columns in django [closed]

Tags:

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?

like image 872
Stephen Avatar asked Feb 16 '10 11:02

Stephen


1 Answers

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) 
like image 111
Felix Kling Avatar answered Sep 18 '22 18:09

Felix Kling