Use columns from gridfield for export

This commit is contained in:
Anton Smith 2016-07-19 08:26:07 +12:00
parent a73f08bd88
commit 4c856c4377

View File

@ -92,6 +92,25 @@ class GridFieldExportButton implements GridField_HTMLProvider, GridField_ActionP
}
}
/**
* Return the columns to export
*
* @param GridField $gridField
*
* @return array
*/
protected function getExportColumnsForGridField(GridField $gridField) {
if($this->exportColumns) {
$exportColumns = $this->exportColumns;
} else if($dataCols = $gridField->getConfig()->getComponentByType('GridFieldDataColumns')) {
$exportColumns = $dataCols->getDisplayFields($gridField);
} else {
$exportColumns = singleton($gridField->getModelClass())->summaryFields();
}
return $exportColumns;
}
/**
* Generate export fields for CSV.
*
@ -100,9 +119,7 @@ class GridFieldExportButton implements GridField_HTMLProvider, GridField_ActionP
*/
public function generateExportFileData($gridField) {
$separator = $this->csvSeparator;
$csvColumns = ($this->exportColumns)
? $this->exportColumns
: singleton($gridField->getModelClass())->summaryFields();
$csvColumns = $this->getExportColumnsForGridField($gridField);
$fileData = '';
if($this->csvHasHeader) {