[Django]-How to sort by within a Django list

2👍

Rather than reinventing the wheel, the solution i propose is to enjoy a reusable app that does it right.

django-tables2
simplifies the task of turning sets of data into HTML tables. It has
native support for pagination and sorting. It does for HTML tables
what django.forms does for HTML forms. e.g.

Its features include:

  • Any iterable can be a data-source, but special support for Django querysets is included.
  • The builtin UI does not rely on JavaScript.
  • Support for automatic table generation based on a Django model.
  • Supports custom column functionality via subclassing.
  • Pagination.
  • Column based table sorting.
  • Template tag to enable trivial rendering to HTML.
  • Generic view mixin for use in Django 1.3.

Screenshot

👤jpic

2👍

Personally I would use something like jQuery tablesorter to solve this. This will save you a roundtrip to the server for each sort.

Docs: http://tablesorter.com/docs/

👤Mikael

1👍

Another option is the use of django-filter. Just check out the example app:

https://github.com/alex/django-filter

👤nopogo

Leave a comment