Column Selector Tab Strip

Selecting and deselecting multiple columns in the column selector using a script.

Looking for a way to select columns displayed in table based on which tab in tab strip is selected.


if ‘ALL’ is selected in tab strip >>>> All the columns are displayed.

if ‘FRUIT’ tab is selected in tab strip >>>> All columns pertaining to fruit are displayed (apples, oranges, etc.)

Hi schumtty,

If you are getting this information trough an SQL query, you can use a custom property(string) on the tab strip. in this property you put a expression like:

if ({Root Container.Tab Strip.selectedTab} = ‘vegetable’, “tomato”,
if ({Root Container.Tab Strip.selectedTab} = ‘fruit’, “apple, orange”,“tomato, apple, orange”))

and you should use this property in your SQL query after the SELECT statement.
I hope it will work.

Hi! Welcome to the forums (and Bart, too, may I add!). :smiley:

If you have a lot of different options, you may want to consider using a switch expression:

switch({Root Container.Tab Strip.selectedTab}, "fruit", "vegetable", "'apples', 'oranges', 'bananas'", "'corn', 'beans', 'asparagus'", "*" )

And, as Bart pointed out, you can then use the results of this custom property to populate your query: SELECT {Root Container.Tab Strip.customProperty} from TABLE...

There’s another way you can use the result of this custom property by hiding or unhiding the table columns. More on that in the next post. :wink:

EDIT: Fixed dead link, updated post to new forum format.

Ok, here’s a method to hide/unhide columns via the Column Attributes Data:
Table Column Tab Strip_2020-02-28_0750.proj (19.1 KB)

The same custom property from above is placed in the table. Work is done by the table’s propertyChange script.:

if event.propertyName=="columnSelect":
	print 'start'
	colSelect=[x.strip() for x in event.source.columnSelect.split(',')]
	print colSelect
	dataIn=system.dataset.toPyDataSet(event.source.columnAttributesData) # get table's attributes
	headers=list(dataIn.getUnderlyingDataset().getColumnNames())         # get the column names. Used later to rewrite the dataset
	dataOut=[]                                                           # empty data
	for row in dataIn:
		print rowList[0], rowList[0] in colSelect                        # convert each row to a python list
		if rowList[0] in colSelect or colSelect[0]=='*':                 # check to see if the column is one to select
			rowList[10]=0                                                # if it is, then turn off the hidden attribute
			rowList[10]=1                                                # otherwise, turn it on.
		dataOut.append(rowList)                                          # add the list to the new data
	event.source.columnAttributesData=system.dataset.toDataSet(headers,dataOut)  # write the new dataset to the column attributes.

This one may take a moment to wrap your head around, and that’s okay. :slight_smile:

The advantage of this is that you don’t need to query the database each time the selection changes. The changes to the table are (almost) immediate, reducing the wait time to process another query. We’re not doing anything with the data from the query itself, we’re just hiding bits and pieces of it.

1 Like