Downloading a perspective table to csv

Hi everyone,

I have a table in Ignition that I am currently downloading successfully in CSV, using a script connected to a download button. All that works, however excel re-orders the columns.

Does anyone know how I can force excel to present the data the same as in Ignition? Is there a sorting option in the system.perspective.download(detailsFilename, myFile) to ensure sorting?

Is the CSV file itself in the correct order (e.g. if you view it in a plain text editor)?

Is your table set up with explicit column ordering via the columns property, with an entry per column with an explicit field property declared?

So I'm querying an SQL Server table, then displaying it in Ignition, then I create a url for people to see it on a webpage. The ordering is correct on the web, and yes I do specify Columns under PROPS and their properties (whether its a string, date, etc.), and I have an explicit ordering.

The issue is when someone hits the download button, what they get in Excel has a different order from the webpage.

Are the columns in the desired order in the SQL query?
It won't matter to the table because you've specified the column.x.field property but I imagine it would for the CSV.

Are you using JSON return format from a named query binding? If so, the data property of the table becomes a list of dictionaries, and the dictionaries do not retain key ordering. (It's a java and jython performance thing.)

If this is the problem, consider keeping dataset return format. If you have been using a transform to add styling to the table, move the query binding to another (custom) property, then transform that property to the table data prop. This leaves the original query result in dataset format, which retains the column order.

(I recommend always using dataset return format--leaves you with access to the original column order, and is a compact representation of the data.)

1 Like

Yes I had a JSON return format and when I change that to dataset it kills my script. I think you are definitely right about this being the source of the issue. I'll try to implement your recommendation.