Search code examples
filteringmulti-selectgoogle-app-maker

Filtering a datasource using multi select wild character


Does anyone know if there is a wildcard character in AppMaker that can be used for all possible values for a field in a query?

I currently have a datasource that is being filtered based on the status using a multi-select widget. What I would like to accomplish is when all values have been de-selected I want to load all the records of that datasource without clearing the entire query in case other filters have been applied. I have it working in-a-sense that I have to explicitly construct my query as such:

widget.datasource.query.filters.Status._in = ['Status Value 1','Status Value 2','Status Value 3']

My current solution is loading the correct data when a value is selected and it correctly shows the union of the query as the values are modified. However, it selects all of the values in my multi-select; which I know is how it is supposed to work.

I tried using widget.datasource.query.filters.Status._contains = ''; and changing the assignment value to no avail. I even tried the opposite approach using _notContains

The intended outcome is to have a filtering dashboard appear much like any website where when no filtering is selected all records are displayed. I was hoping to find a wildcard character that would load all of the records. Just trying to find a way to mimic other website filters with all records when none are selected.

Thanks for the time!


Solution

  • So the easiest solution here is to set up your Multiselect as follows:

    Options binding:

    @models.YourModel.fields.Status.possibleValues
    

    or if you don't have the possible Status values in your model then set your options binding to:

    ['Status Value 1','Status Value 2','Status Value 3']
    

    Values binding:

    @datasource.query.filters.Status._in
    

    Now anytime you select any choices in the multiselect, the query will only include records that include the selected choices. And if you deselect all choices the query will ignore that filter or treat it as an empty array of values, therefore returning all records unless you applied other filters.