tags:

views:

173

answers:

2

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?

+3  A: 

Javascript? There are plenty of table sorters out there:

I like the first one a lot...easy to use and flexible. thnx
Stephen
+1 for tablesorter
Zach
+2  A: 

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)
Felix Kling