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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Export Data from the front end [solved]


Go to End


3 Posts   1468 Views

Avatar
cumquat

Community Member, 201 Posts

19 August 2014 at 2:38am

Hi ya,

ok i'm hoping this is a simple one and its just my lack of sleep that is stopping me from getting the answer. I have created an export fields function that works great from the model admin as per the http://doc.silverstripe.org/framework/en/reference/modeladmin

What i would like to do is to run the export function from the front end just by pushing a button on a management page.

Any pointers?

regards

Mick

Avatar
cumquat

Community Member, 201 Posts

20 August 2014 at 12:24am

Anyone?

Currently i have this function in my model admin and it works perfect but i don't want to give the users backend access to the system so just want to export all the records at a push of a button.

Hope some one can help.

Mick

public function getExportFields() {
        return array(
        'ID' => 'ID',
        'Area.Name' => 'Area',
        'DateMissing.Nice' => 'Date Missing',
        'MisperType.Name' => 'Misper Type',
        'Gender' => 'Gender',
        'Age'=> 'Age',
        'TOD' => 'Time of Day',
        'IPPGR' => 'IPP Grid',
        'DateFound.Nice' => 'Date Found',
        'FindGR' => 'Find Grid',
        'Dist' => 'Distance from IPP (km)',
        'Location.Name' => 'Location Type',
        'Survivability.Name' => 'Survivability',
        'DestGR' => 'Destination Grid',
        'TrackOff' => 'Track Offset (m)',
        'AreaType' => 'Area Type',
   		'DateCalledOut' => 'Callout Date',
   		'MissingLoc.Name' => 'Missing From',
        'Notes' => 'Notes'
        );
    }

Avatar
cumquat

Community Member, 201 Posts

21 August 2014 at 1:46am

Ok got around this using a gridfield and a little help from here [link]http://stackoverflow.com/questions/17502299/how-to-export-all-rows-as-csv-in-modeladmin-silverstripe-3-1 [/link]

public function AllSearches() {
        $config = GridFieldConfig::create();
        $config->addComponents(new GridFieldExportAllButton());
        $form = Form::create(
            $this,
            "AllSearches",
            FieldList::create(
                LiteralField::create("LiteralField","<legend>Export All Search Data</legend>" ),
                LiteralField::create("LiteralField","<div class='large-12 medium-12 columns'>" ),
                    GridField::create('SearchGrid', 'Searches', new DataList('TheSearch'), $config),
                LiteralField::create("LiteralField","</div>" )
            ),
            FieldList::create(
              
            ),
           RequiredFields::create(array())
        )->addExtraClass('SearchExport');
        return $form;
    }