Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Userforms - Sorting fields in CSV export


Go to End


3 Posts   2652 Views

Avatar
Juanitou

Community Member, 323 Posts

23 October 2009 at 3:47am

Hi!

When exporting the submissions of an user form to a CSV file, the order of the fields is not respected, I guess they are ordered by creation date or so… How can I get those CSV columns properly ordered? It baffles me since a <% control Fields %> outputs fields in the desired order.

Thanks in advance,
Juan

Avatar
JonoM

Community Member, 130 Posts

17 March 2010 at 4:05pm

Hi Juan,

I realise this is an old post but I had the same problem and hopefully this will help someone else.

I changed the SQL statement on line 89 of SubmittedFormReportField.php from

$tmp = DB::query("SELECT DISTINCT `Name`, `Title` FROM `SubmittedFormField` LEFT JOIN `SubmittedForm` ON `SubmittedForm`.`ID` = `SubmittedFormField`.`ParentID` WHERE `SubmittedFormField`.`ParentID` IN (" . implode(',', $inClause) . ") ORDER BY `SubmittedFormField`.`ID`")

to

$tmp = DB::query("SELECT DISTINCT `Name` , `Title` FROM ( (SELECT `Name` , `Title` FROM `SubmittedFormField` LEFT JOIN `SubmittedForm` ON `SubmittedForm`.`ID` = `SubmittedFormField`.`ParentID` IN (" . implode(',', $inClause) . ") ORDER BY `SubmittedFormField`.`ID`) AS `tmp` )")

It basically forces the ordering to happen before the table is reduced with the distinct command - apparently DISTINCT and ORDER BY don't work well together.

Avatar
MateuszU

Community Member, 89 Posts

8 October 2010 at 1:11pm

Hi guys,

This has been included in http://open.silverstripe.org/ticket/6072 changeset. JonoM, I've used your query, but modified it so the most recent submission ordering takes precedence. Would be nice if someone could cross-check it :)

Cheers,
Mateusz