The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Changing the order of columns in a CSV export


This Discussion is public


Hi All,

I am aware of a filter to reduce the number of columns in a CSV file but need some code to change the order of the columns.

Here is the link to the filter for reducing the columns.

Apparently something needs to be done with the array $headings.  but I'm at a loss how to do this, or where.

If you've had success with this before I'd love to hear from you.

Kind Regards,



PHP has quite a few array sorting functions, including several for user defined sorting.

You could probably use the filter to intercept the headings array and try sorting it somehow, but I suspect you may be better off intercepting it and redefining it from scratch. In other words, empty it out and redefine it.

Hi Victor,

Thanks for your reply.  That's probably a bit beyond my skill set right now.  I did have a poke around to see where $headings exist and how it is constructed/managed.  But got lost.

Other options for changing the order of the columns rely on Views or datatables and have the results brought to the browser.  My worry with this is that as the dataset grows it might break the browser.  So a backend solution is preferable.

Thanks again for your time.



I don't think you have to worry about overloading the browser with either views or datatables. Both use Ajax and pull data as needed. You'll never download an entire database of content at one time. I've built views with datatables that have had over 100 fields that the client required for export, but we only displayed about 10 of the fields on the screen. All the rest were hidden.

Discussion closed.