datasette-dashboards icon indicating copy to clipboard operation
datasette-dashboards copied to clipboard

Add multiple choice select filter type

Open rclement opened this issue 2 years ago • 2 comments

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 select tags can specify a multiple attribute allowing multiple values selection of options: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/multiple
  • HTML checkbox input using a fieldset: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input/checkbox

rclement avatar Feb 24 '23 11:02 rclement

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

rclement avatar Feb 25 '23 14:02 rclement

An upstream issue has been opened in Datasette: https://github.com/simonw/datasette/issues/2035

rclement avatar Mar 08 '23 18:03 rclement