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.

Form Questions /

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

TableListField custom CSV not working?


Go to End
Reply


2 Posts   1522 Views

Avatar
Sparrowhawk

Community Member, 33 Posts

15 December 2009 at 12:37am

Edited: 15/12/2009 12:37am

Hi,

I have amended the CMS form for one of my pages to include a TableListField.

This works fine, it shows the 4 columns I have asked it to show for the records in table ProgrammeLaunch.

However, it is ignoring my custom query that is set for the CSV export (ie on the form I show just 4 fields, but in the CSV export I want to see more fields, but only the 4 fields listed for the form view are being exported. Here is the code:

class ProgrammeLaunchPage extends Page
{
    static $db = array();

    function getCMSFields() {
        $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Content.Responses',$this->getProgrammeLaunchAnswersAsTLF());

        return $fields;
    }

    /**
     * Returns the questionnaire answers as a TableListField
     *
     * @return TableListField
     */
    protected function getProgrammeLaunchAnswersAsTLF() {

        // Fields to display at the top level
        $fieldList = array(
            'AttendeeName'      => 'Name',
            'AttendeeJobTitle'  => 'Job Title',
            'AttendeeCompany'   => 'Company',
            'LastEdited'        => 'Submitted',
        );

        $tf = new TableListField('Responses', 'ProgrammeLaunch', $fieldList);

        $tf->setFieldCasting(array('LastEdited' => 'Date->Nice'));

        // what is user allowed to do?
        $tf->setPermissions(array('show', 'export', 'delete', 'print'));  // export permission allows CSV exporting

        //Page navigation
        $tf->setShowPagination(true);
        $tf->setPageSize(12);

        // CSV output def
        $customCsvQuery = new SQLQuery('*', 'ProgrammeLaunch', null, 'AttendeeName');
        //die($customCsvQuery);

        $tf->setCustomCsvQuery($customCsvQuery);

        return $tf;
    }

}

If I uncomment the die statement, the SQL produced is valid: SELECT * FROM ProgrammeLaunch ORDER BY AttendeeName

What am I missing?

Many thanks for any help

Avatar
Sparrowhawk

Community Member, 33 Posts

15 December 2009 at 12:49am

Edited: 15/12/2009 1:40am

I've found a solution, although it does not provide an explanation for the above, so if anyone can explain why the above does not work, I'd be very grateful.

Solution is to use $tf->setFieldListCsv($csvFieldList); instead, where $csvFieldList is an array of field names => field descriptions