Exporting Perspective Table data to CSV

Hello,

I have been reviewing the forum posts on csv export from ignition and cant seem to find my use case so I figured I would open a topic.

I have a page with a power table and a little dock that pops out on right side to help the user toggle on/off which columns they want on the table. On that dock they also have an export button.

The export button invokes a perspective message called ExportData which is handled in the root of the page.

this is my ExportData handler code.

#      root > table-flex > body > table
	table = self.getChild("Table Flex").getChild("Body").getChild("Table")
#      create a list of columns that are selected by user
	colsToKeep = [col["field"] for col in table.props.columns if col["visible"]]
#	first row of data is headers
	data = [colsToKeep]
	for el in table.props.data:
		rowData = [v["value"] for _,v in el.items() if _ in colsToKeep]
		data.append(rowData)
	
	newCsv = system.dataset.toCSV(data)	
	system.perspective.download("Export.csv",newCsv)

for some reason when i export to csv i get 2 rows of data.

I was under the impression that if I feed toCSV() a list of lists with first row as header that i would get a csv output?

Any idea what i might be missing here?

Perspective doesn't have a Power Table component. Vision does.
In Perspective the component is called "Table".

system.dataset.toCSV() requires a dataset.

#      root > table-flex > body > table
	table = self.getChild("Table Flex").getChild("Body").getChild("Table")
#      create a list of columns that are selected by user
	colsToKeep = [col["field"] for col in table.props.columns if col["visible"]]

	data=[]
	for el in table.props.data:
		rowData = [v["value"] for _,v in el.items() if _ in colsToKeep]
		data.append(rowData)
	
	newCsv = system.dataset.toCSV(system.dataset.toDataSet(colsToKeep, data)	
	system.perspective.download("Export.csv",newCsv)

my bad; i'm definitely working with perspective; been in vision land for past 3 years.

1 Like

shizam!

This is exactly what I was missing. Thanks, my app just leveled up!

1 Like