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.

All other Modules

Discuss all other Modules here.

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

Userforms - Sorting fields in CSV export


Reply

3 Posts   1845 Views

Avatar
Juanitou

23 October 2009 at 3:47am Community Member, 323 Posts

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

17 March 2010 at 4:05pm Community Member, 103 Posts

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 [url=http://dev.mysql.com/doc/refman/5.0/en/distinct-optimization.html]don't work well together[/url].

Avatar
MateuszU

8 October 2010 at 1:11pm Community Member, 89 Posts

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