Creating a checkbox filter that applies only when checked – or unchecked

A checkbox filter is one of the most intuitive user constraints you can add to a grid. The user simply checks a box and the rows of the underlying grid are immediately filtered to reflect the condition labeled on the checkbox.

Upload

In earlier versions of Valence, a checkbox filter condition was active regardless of whether the box was checked or unchecked. That is, one specific filter condition would apply when the box was checked, while another condition would apply when unchecked. But beginning with build 5.2.20200323.0 checkbox filters were enhanced so they can optionally be applied only when the box is checked, or only when the box is unchecked, thereby allowing you to specify when no filter condition should be applied at all. This makes it possible to create “all values” versus “one value” filter conditions on checkboxes. 

To illustrate this concept in action, let’s walk through the process of creating a checkbox that, when checked, will limit the results of a grid of customers to a specific country. We’ll start by going into Nitro App Builder (NAB) and creating a data source over the trusty DEMOCMAST customer master file included with Valence. A simple SQL-based data source selecting all the columns will do — i.e., SELECT * FROM DEMOCMAST.

The next step is to create a basic grid widget over the data source. Once you’ve got some pertinent columns selected for the grid, switch over to the Filters tab. Let’s say we want to add a checkbox filter that, when checked, will limit the list to American customers only, but when left unchecked the list is not filtered at all, thus showing all customers. To do this, check the box next to the “Country” column, and override the description to match the condition we’re creating (i.e., “US Customers Only”), as depicted here…

Upload

When you click in the “Transform to Checkbox” cell, you’ll be presented a pop-up window with the configuration for the checkbox filter.  Since we only want the list to be filtered when the checkbox is checked, we should set the “Filter Widget On” setting to “Checked” and put a custom value of “United States” as shown here…

Upload

You can see this checkbox working in the grid right away by switching back to the Configure tab…

Upload

Now, what if you wanted the checkbox to include multiple values for the customer list?  For instance, let’s say you wanted to give the users an option to limit the list to customers in the Scandinavian countries of Sweden, Norway and Finland?  Since you can only specify a single value in the filter condition, you can’t set this up solely within the grid widget configuration. But with a slight tweak of the data source, you can still incorporate this kind of checkbox filter. Here’s how:

First, go back into the data source and add a custom column called “is_Scandi”, which will be set to a boolean value predicated on the country being one of those three Scandinavian countries. In the case of an SQL data source, it should result in a statement like this (our custom column addition in bold):

select  CUSNO,  CNAME,  CADDR1,  CCITY,  CSTATE,  CCOUNTRY,  CZIP,  case when CCOUNTRY in (‘Sweden’,’Norway’,’Finland’) then ‘true’ else ‘false’ end as IS_SCANDI from DEMOCMAST

With that data source updated and saved, you can now go back into the grid widget and add a filter on the IS_SCANDI column, even though the column is not included on the grid itself.  In this case we could set the description to “Scandinavia Only” and filter on a checked value of the default boolean value (“true”)…

Upload

And with that in place, your users now have an easy way to use a single checkbox action to filter on multiple values…

Upload