Hi guys, Im just wondering my filter or my script is not working when i call it. So im just wondering what i can do to fix this or maybe improve it. Please and thank you.
def filterPowerTable(ds, textValue):
"""
filters a dataset based on the ID column matching the text input value.
Example:
filtered = filterPowerTable(ds, textValue="12345")
Arguments:
ds: The dataset to filter.
textValue: The value entered in the text input.
"""
pds = system.dataset.toPyDataSet(ds)
output = []
for row in pds:
if all(row["ID"] == value in (textValue)):
output.append(row)
return system.dataset.toDataSet(list(ds.columnNames), output)
And for my code call in the text propertyChange:
textValue = system.util.getProperty(text)
ds = event.source.parent.getComponent('powertable')
filtered = WWB.Utilities.dataset.filterPowerTable(ds, textValue)
I fixed your code formatting; you have to use three 'backticks', `, not single quotes.
The most immediate problem I see is the property change event:
- Never use a
propertyChange
event in Vision that's not immediately filtering which property it cares about, as the first line:if event.propertyName == "textValue":
system.util.getProperty
is not doing what you think it's doing; it's retrieving the value of an overall "system property" for the entire client/designer process, not the property of an individual component. Use the chain-like icon in the top right of the script editor to select the property you care about. You should have a path like event.source.textValue
- reading properties from components is as simple as that.
- Even if everything else you were doing was working the way you wanted it to - you're running your
filterPowerTable
function, and returning a new result, and even assigning that result to a new variable...but you're not assigning it back to the component. You need a final line like:event.source.parent.getComponent("powertable").data = filtered