Problem exporting table data to Excel

Hi there,
I have a button in my page thta should export table data to excel.
Everything worked fine before I added a script to change the style of rows based on a value.

def transform(self, value, quality, timestamp):
	return [
		{'style': {"backgroundColor": "#D62F2F4D" if row['VuotoErr'] > 60 else "none"}, 'value': row} for row in value
		]

My button onClick event is:

	def jsonToDataset(list):
		columns = dict(list[0]).keys()
		data = []
		for item in list:
			row = []
			for column in columns:
				cellValue = item.get(column, '')
				try:
					dict(cellValue)
					cellValue = cellValue['value']
				except:
					pass
				row.append(cellValue)
			data.append(row)
		return system.dataset.toDataSet(columns, data)
		
	json = self.getSibling("tblDeodorazione").props.filter.results.data
	if not json:
		json = self.getSibling("tblDeodorazione").props.data	
	data = jsonToDataset(json)
	Excel_xlsx = system.dataset.toExcel(True,[data])
	system.perspective.download("rptDeodorazione.xlsx",Excel_xlsx)
	

if I write something in the table filter the output is correct:

but if I don't wrtite anything on the filter here is the result:



I think that, for sure, the problem is related to the new json structure:

But if the export script works when I have something written in the table filter, then, why it doesn't work if nothing is written there, the structure of the json doesn't change.
I do not understand.
If anyone has any suggestions I would be very grateful.
thanks

But it does change. You are moving the row into the nested value key.

Consider binding the raw data (in dataset format) to a custom property. Transform that custom property into the table's data property to provide the styling as you have it now. Have the export button simply use the dataset in the custom property.

1 Like

well, I tried but I don't really know how to accomplish that.
I've used another work around, I've used the named query that fill the table and I use export button like this:

parameters  = {"parStartDate":self.getSibling("startDate").props.value, "parEndDate":self.getSibling("endDate").props.value}
	data = system.db.runNamedQuery("UGP9/qryDeodorazione", parameters)	
	data = system.dataset.toExcel(True, [data])
	system.perspective.download("rptDeodorazione.xlsx",data)

My goal was to export values that match table filter only to excel, my solution works, but it's exports all data between startDate and endDate....better than nothing.
For now I'm making it work fine. I'll do some more research...
Thank you very much