-
Is possible to sort facets alphabetically? Thanks in advance, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
It's not at the moment, but this is an interesting feature idea. Right now you can achieve this using a custom SQL query, for example for the list of states on https://congress-legislators.datasettes.com/legislators/legislator_terms?_facet=state&_facet_size=max You can run this: select
state,
count(*)
from
legislator_terms
group by
state
order by
state Or if you want to be able to click a link to view the results by state: select
state,
count(*),
'https://congress-legislators.datasettes.com/legislators/legislator_terms?state=' || state as url
from
legislator_terms
group by
state
order by
state You could even write a custom faceting plugin that does this, but it would be tricky as there aren't any good examples of faceting plugins at the moment: https://docs.datasette.io/en/stable/plugin_hooks.html#register-facet-classes I've opened an issue here to think about how this could work in Datasette itself: |
Beta Was this translation helpful? Give feedback.
-
Hi Simon, Fantastic!! Thanks a lot for the answer. Best, |
Beta Was this translation helpful? Give feedback.
It's not at the moment, but this is an interesting feature idea.
Right now you can achieve this using a custom SQL query, for example for the list of states on https://congress-legislators.datasettes.com/legislators/legislator_terms?_facet=state&_facet_size=max
You can run this:
https://congress-legislators.datasettes.com/legislators?sql=select+state%2C+count%28*%29+from+legislator_terms+group+by+state+order+by+state
Or if you want to be able to click a link to view the results by state: