Hello!
I´ve got a button and I would like to export the content of a table "tblSummary" when I click on it.
filePath = system.file.getTempFile("csv")
with open(filePath, "w") as file:
for row in data:
file.write(",".join(str(item) for item in row) + "\n")
system.perspective.download(filename, File(filePath))
table = self.getSibling("tblSummary")
data = table.props.data
csv_data = [[col for col in row.values()] for row in data]
# Write to a CSV file and trigger download
write_csv(csv_data, "exported_data.csv")
I using this code on the button Script´s configuration
doesn´t download the csv when I launching Perspective session.
You didn't tell it to. You told it to export it to a file on the gateway.
1 Like
Oh, ok thanks Transistor, adding that part, cheers
I added this code to my button:
def runAction(self, event):
component = self.getSibling("CO2Table")
csv = system.dataset.toCSV(component.props.data)
system.perspective.download("myExport.csv", csv)
and now I can download the table content as a excel file.
step by step:
- Identify Hierarchical Structure: Know the relative position of your button and table component to determine which navigation method (
getParent
, getChild
, getSibling
) to use.
- Use Component Navigation Functions: Apply the proper function to locate the table relative to the button.
- Export Table Data: Utilize the appropriate Ignition Perspective functions to retrieve the dataset and initiate a download.
This has a very strong smell of ChatGPT. You have been warned about posting AI answers several times.
Please state clearly if this is your work or if you got it from AI.
1 Like
You right, I came with the code, then get the explanation from chatGPT to make the post easier to understand.
Yes, and ChatGPT gives a poor answer. Using hierarchical structure means that the application will break if anything gets moved. The preferred method is to use message handlers.
Please stop posting ChatGPT. See FAQ - Inductive Automation Forum.
Post Only Your Own Stuff
You may not post anything digital that belongs to someone else without permission. You may not post descriptions of, links to, or methods for stealing someone’s intellectual property (software, video, audio, images), or for breaking any other law.
This includes artifacts of large language models or other "AI" tools, such as ChatGPT. While LLMs are often useful, they lack useful context for Ignition development and should be used sparingly for specific purposes. Posting LLM output as your own content with no human authored content attached is not a useful post, and may earn you a warning.
2 Likes
Ok, going to learn to use message handlers