Filtering values to display in a Property Control list box


There are many times when you want to use a Property Control to display a list of Columns, but only show a subset of Columns rather than all of them.  This could be because only certain columns are relevant for your analysis, or it could be because you have so many columns, it would be unusable to display them all.  If you want to limit columns based off what is relevant for your analysis, you could use something like the datatype and choose to display only columns with a given data type.


You can do this when you create the Property Control by specifying the datatype you want to limit to in the 'Selectable columns' field shown below.


 

 

In this case, we are choosing to only show columns where the datatype is a string.


What if you wanted to allow the consumer to define what to show in the property control?  We can do this with a combination of Property Controls and Script Controls.  This can be very useful if you have a Data Table with too many columns to show in a Property Control.


First, we create an Input field Property Control:

 

 
This Property Control is going to let a consumer enter a search string to use for selecting what Columns to display.  


Then we create a multi-select List Box Property Control. This will be the Property Control which displays all the Columns matching our search criteria. This Property Control  allows us to use properties to limit the values shown in the list,  as we saw earlier when we limited by showing only String Columns. So, we will create a new property called isIncluded, and only show Columns where isIncluded is true.  This is done by adding isIncluded:True into the 'Selectable columns (limit through expression)' field:


 

 

We now need to create the isIncluded property. This can be created in a variety of places, but the easiest may be to go to Edit > Column Properties and create it there.
 


Then we add a Script Control. The Script Control will read the search criteria from the input Property Control, use it to find matching Columns in the Data Table, and then set the isIncluded property on those Columns to True.

The Script Control will take in the value from the input Property Control as the and call is pattern. It will then loop through each Column and use the Python regular expression object to search for a match with the Column name and the pattern. If there is a match, the isIncluded property is set to True, otherwise, False.


 

The End Result

Entering a search expression in the input field and then clicking the 'Filter Columns' button will display only matching Columns in the list box Property Control.  For the search expression , use the pipe character (|), to add multiple search criteria. Other syntax follows Python regular expression syntax.


 

 

To learn more about Property Controls, please take either our Authoring Bootcamp  or our 3.1 Delta Training course. To learn more about Script Controls, please take either our Developer Bootcamp or our Automation APIs using IronPython course.

 

Also, remember to sign up for our free Analytics in Action webinar series, run monthly.