Marking Records using Property Controls


By default Property Controls cannot be attached to a marking selection. However, by combining Script Controls with Property Controls, we can create the desired functionality.

The first step is to create the Property Control(s). There are a variety of different ways to do this logic. First, you can use list box controls to show unique values in a column, and then mark the selected values. Or you can have one drop down to allow the user to select a column, and then a value to search for, and mark all rows where the specified column has the specified value.  We can even add multiple Property Controls to allow more complex logic (like if Col A = 3 and col B = 'Boston') and we can also use logical operators, like less than and greater than.

Assume our data table includes information about various cars, including make, model, sticker price, engine size, fuel economy, etc'.  We want to create a Property Control that allows a user to specify a minimum sticker price. For this we can use an Input field control type, and have the control attach to a Document Property of type real (since the sticker price column, MSRP, is also a real).


We then need to create a Script Control which will mark the rows where the sticker price is greater than or equal to the value specified in the Property Control.  The Control will read in the minVal property created earlier as an input parameter.


 

 

The entire script is below:

from Spotfire.Dxp.Data import IndexSet
from Spotfire.Dxp.Data import RowSelection
from Spotfire.Dxp.Data import DataValueCursor
from Spotfire.Dxp.Data import DataSelection

rowCount = Document.ActiveDataTableReference.RowCount
rowsToInclude = IndexSet(rowCount,True)
rowsToMark = IndexSet(rowCount,False)


cursor1 = DataValueCursor.CreateFormatted(Document.ActiveDataTableReference.Columns["MSRP"])


for  row in  Document.ActiveDataTableReference.GetRows(rowsToInclude,cursor1):
   rowIndex = row.Index
   value1 = cursor1.CurrentValue
   if float(value1) >= float(minVal):
              rowsToMark.AddIndex(rowIndex)

Document.ActiveMarkingSelectionReference.SetSelection(RowSelection(rowsToMark), Document.ActiveDataTableReference)


When complete the functionality will look something like below:

.


 
Remember that using this capability is not limited to a single column, so you can add in as much complexity into your logic a you want.

If you are interested in learning more about the script listed above, or how to accomplish similar functionality, please consider taking our Script Controls training course.

We have also just added a new section on our Community called Analytics Exchange where community members can post a variety of assets, including Script Controls, Expressions, Analysis Files shared via the Web, S+ and R Scripts and Data Functions, and Sample Data Sets.  I am including the script above in the Script Controls section. Please remember to check out the Exchange to search for and find useful content, and also please feel free to post content you have created which you wish to share with others.