Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to ensure consistent ordering when sorting? #861

Open
ddahan opened this issue Aug 11, 2022 · 1 comment
Open

How to ensure consistent ordering when sorting? #861

ddahan opened this issue Aug 11, 2022 · 1 comment

Comments

@ddahan
Copy link

ddahan commented Aug 11, 2022

When sorting the table by clicking on a header, if there are rows that have the same value, the order can not be consistent from one query to another. Is there a way to specify a "secondary" sorting criteria?

For example, when user clicks on the price header to sort rows by price, behind the scene I'd like to have ordering = (price, pk) sothat the result is guarantee to be the same, given the same queryset.

For now, I succeeded with :

price = tables.Column(order_by=["price", "id"])

However, doing this for every column is tedious, there must be a better way.

Thanks.

@ddahan ddahan changed the title How to ensure consistent order when sorting? How to ensure consistent ordering when sorting? Aug 12, 2022
@jieter
Copy link
Owner

jieter commented Dec 27, 2022

However, doing this for every column is tedious, there must be a better way.

Currently, there is no way to define an extra field to sort on. I'm not convinced that this is a feature worth implementing: certain columns would not need this, how do you suppose to configure that? I'd say this case should be solved by explicitly adding the order_by arguments to the columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants