datasette-dashboards
datasette-dashboards copied to clipboard
Add multiple choice select filter type
Add an option to select filter type allowing to select multiple values.
Example:
...
filters:
source:
name: Source
type: select
multiple: true
options: [Source 1, Source 2, Source 3]
default: [Source1, Source 2]
...
2 potential implementation:
- HTML
selecttags can specify amultipleattribute allowing multiple values selection of options: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/multiple - HTML
checkboxinput using afieldset: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input/checkbox
Might not be an easy solution for this:
- SQLite does not support passing a list as bound named parameter
- No workaround is built into Datasette to overcome this restriction
- Some frameworks (e.g. Django) are expanding the query with the appropriate number of arguments in the "IN" clause
Here is a sample query URL with 2 values for the source parameter:
https://datasette-dashboards-demo.vercel.app/jobs?sql=select+count(*)+as+%22count%22+from+offers_view+where+source+in+(%3Asource)%0D%0A&source=Apec&source=RegionsJob
Datasette only retrieve the first value and generate a form with a single entry for the source parameter.
The only way to perform the "IN" clause is to use multiple named parameters for each value in the list: https://datasette-dashboards-demo.vercel.app/jobs?sql=select+count%28*%29+as+%22count%22+from+offers_view+where+source+in+%28%3Asource1%2C+%3Asource2%29%0D%0A&source1=Apec&source2=RegionsJob
Sources:
- https://github.com/simonw/datasette/issues/1304
- https://stackoverflow.com/a/1310001
An upstream issue has been opened in Datasette: https://github.com/simonw/datasette/issues/2035