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

Option in metadata.json to set default sort order for a table #702

Closed
simonw opened this issue Mar 21, 2020 · 5 comments
Closed

Option in metadata.json to set default sort order for a table #702

simonw opened this issue Mar 21, 2020 · 5 comments

Comments

@simonw
Copy link
Owner

simonw commented Mar 21, 2020

If you access the table page without any ?_sort or ?_sort_desc arguments it currently defaults to order by primary key - would be neat to be able to change that.

@simonw simonw changed the title Option in metadata.json to set default sort ordrer for a table Option in metadata.json to set default sort order for a table Mar 21, 2020
@simonw
Copy link
Owner Author

simonw commented Mar 21, 2020

I can solve #677 (The first time you click sort by ID it should show you results in reverse order) at the same time.

simonw added a commit that referenced this issue Mar 21, 2020
@simonw
Copy link
Owner Author

simonw commented Mar 22, 2020

I'm going to mirror the URL syntax here, so the options in metadata.json will be:

  • "sort": "created" to default sort by created
  • "sort_desc": "created" to default sort by created descending

It will throw an error if you try to define both.

If I add the ability to sort by multiple columns in the future (#197) I can allow a list of columns here - though I'm not sure how I would represent "sort by created asc, title desc" in that case.

If you want to disable user-specified sorting you can do so using the existing "sortable_columns": [] mechanism.

@simonw simonw closed this as completed in 236aa06 Mar 22, 2020
@simonw
Copy link
Owner Author

simonw commented Mar 22, 2020

@simonw
Copy link
Owner Author

simonw commented Mar 22, 2020

Found a bug: if you click on a column with a default sort order applied to it you get: "Cannot use _sort and _sort_desc at the same time"

@simonw simonw reopened this Mar 22, 2020
@simonw simonw closed this as completed in a498d0f Mar 22, 2020
simonw added a commit to simonw/covid-19-datasette that referenced this issue Mar 24, 2020
Using new, unreleased Datasete feature:
simonw/datasette#702
simonw added a commit to simonw/covid-19-datasette that referenced this issue Mar 24, 2020
@simonw simonw added this to the Datasette 0.39 milestone Mar 25, 2020
@simonw
Copy link
Owner Author

simonw commented Mar 25, 2020

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

No branches or pull requests

1 participant