Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » Userforms - Sorting fields in CSV export

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1795 Views
  • Juanitou
    Avatar
    Community Member
    323 Posts

    Userforms - Sorting fields in CSV export Link to this post

    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

  • JonoM
    Avatar
    Community Member
    103 Posts

    Re: Userforms - Sorting fields in CSV export Link to this post

    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.

  • MateuszU
    Avatar
    Community Member
    89 Posts

    Re: Userforms - Sorting fields in CSV export Link to this post

    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

    1795 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.