Francesco Bellei
Francesco Bellei

Reputation: 23

How can I clear a specific filter without clearing all filters?

Background:

I am creating an app that stores record of trainings that employees in a company took in table. I want to filter the rows of the table based on training name and/or employee name. I was able to figure out this first part, and I was able to create a button that clears all the filters and reloads the entire table using the clearFilters() function.

Problem:

I want to create two buttons that clear the filter selections one ("All Trainings") for the training name and one ("All Employees") for the employee name. To be more clear, when I click on the "All Trainings" button, I want to clear the filters on the training name, but not on the Employee name. This will become useful once I have a table with multiple fields that I want to filter, and I want to navigate the table without having to reset all fields every time.

I tried searching the functions available on Google App Maker, but there was nothing that seemed to be able to solve my problem. Any suggestions?

Upvotes: 1

Views: 1242

Answers (3)

Steve Johnson
Steve Johnson

Reputation: 182

From the Reference about datasources:

https://developers.google.com/appmaker/models/datasources#query_datasources

Like field filters, assigning null to a relation filter property clears that restriction.

So, something like:

datasource.query.filters.Employee._contains = null;
datasource.load();

should work for you.

Upvotes: 2

Jason Liu
Jason Liu

Reputation: 176

Can you simply take 3 steps in your onClick handler? (1) clear all filter (2) set the employee name filter (3) load data

Upvotes: 0

Adam Bergeron
Adam Bergeron

Reputation: 525

I am sure there is a better way to do this, so you may want to wait for someone smarter to chime in, but I BELIEVE you can just have your button clear the filters, but reapply a new filter.

So for my situation I have the table do a filter for items that are listed as "Complete", so those are hidden when the user opens the page.

Then, when the users filter another field and want to clear out that search I didn't want the "Complete" items to reappear (which is what happened when I just used the clearFilters() function. So my workaround was to make the clear button actually clear the filter, but apply the original "Complete" filter.

So for my OnClick action, for my "Clear Button" I have:

widget.datasource.query.clearFilters();
widget.datasource.load();
app.closeDialog();
var datasource = app.datasources.TestModel;
 datasource.query.filters.Status._notContains = 'Complete';
 datasource.load();

The

widget.datasource.load();
    app.closeDialog();

May be redundant/unnecessary.

Upvotes: 1

Related Questions