Adding elements to Table Column Defs

I understand that you can use table column defs to control which columns appear on a Perspective Table in an active session.

I’m trying to set up a Perspective table where my dataset has a bunch of historic tags in it (static selections in the designer’s data source) and I control which tags are displayed by programatically controlling the table defs. I just noticed that the python documentation for perspective has been updated but I thought it would be good to ask about this before I dig too deeply to start off on the right foot.

My plan was to have a bunch of toggle buttons that represent each of my data points and filter the columns displayed on my Table based on the status of those.

I haven’t found a Python method that allows me to add and remove array elements from my table defs but I might be thinking about this the wrong way. I have found property change scripts and I am able to manipulate properties on other controls using those.

I understand Message Handlers but prefer a property change script in this instance because I don’t have to traverse my list of toggle buttons (over 100) to see which ones are checked.

It seems that I should be able to create another element in the tabledefs array and push a property to it to tell it what field to display.

Can someone point me in the right direction on this?

Hi Steve,

Apologies for the delay. Did you come up with a solution for your problem? The toggle buttons are meant to add or remove column configs, is that correct? If so, we have plan to add a hide property to column configs so that you can toggle their visible state that way. If there are any other features you think might be useful, please let us know.

-Yousuf

I haven’t had time to work on it. I think the answer is either to do this (per this post Perspective table editing help)

import json
json.reads

columnJSON = ‘’
columnSet = []
for i in range(columnCount):
columnSet.append(json.reads(columnJSON % ()))
columnSet[i][‘field’] = ‘Column Name’

myTable.props.columns = columnSet

or maybe to choose the dataset to return as json. I’ve been tied up with other things so haven’t had a moment to try either solution.

The big downside of doing it programmatically the raw way is that when the definition changes, as it has in 8.0.2, you have to redo your script too. Cost of doing business, unfortunately. (Not that I would sniff at an API that took care of all the bookkeeping for you.)

1 Like