morlandi / django-ajax-datatable

A Django app which provides the integration of a Django project with the jQuery Javascript library DataTables.net
MIT License
208 stars 64 forks source link

Allow multiple sorting for each column #22

Open morlandi opened 3 years ago

morlandi commented 3 years ago

Use case: you have a list of addresses like:

street number
aaa 3
aaa 10
aaa 10/A
aaa 2/B

Suppose that an hidden "normalized_number" has been added to support "natural sorting":

street number normalized_number
aaa 3 00000003
aaa 10 00000010
aaa 10/A 00000010/A
aaa 2/B 00000002/B

In this case, you wish to show (street + number) but sort on (street, normalized_number).

This might be solved with the optional "sort_field" column attribute, i.e.:

'sort_field': 'street,normalized_number'

then refactoring sort_queryset() accordingly