Skip to content

Add multiple choice select filter type #54

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

Open
rclement opened this issue Feb 24, 2023 · 2 comments
Open

Add multiple choice select filter type #54

rclement opened this issue Feb 24, 2023 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@rclement
Copy link
Owner

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:

@rclement rclement added the enhancement New feature or request label Feb 24, 2023
@rclement
Copy link
Owner Author

rclement commented Feb 25, 2023

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:

@rclement rclement changed the title Add multiple select filter Add multiple choice select filter type Feb 25, 2023
@rclement rclement added the help wanted Extra attention is needed label Mar 8, 2023
@rclement
Copy link
Owner Author

rclement commented Mar 8, 2023

An upstream issue has been opened in Datasette: simonw/datasette#2035

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant