Skip to content

Commit

Permalink
support custom format and uuid by default
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Jan 2, 2023
1 parent 43195bb commit 834b05e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions _config/excel-import-export.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
---
Name: excel-import-export
After:
- 'framework/*'
- "framework/*"
---
LeKoala\ExcelImportExport\ExcelImportExport:
default_writer: 'Xlsx'
default_writer: "Xlsx"
allowed_extensions:
- csv
- ods
- xlsx
- xls
- txt
export_format:
Uuid: Nice
SilverStripe\Admin\ModelAdmin:
export_csv: false
export_excel: true
Expand Down
11 changes: 9 additions & 2 deletions src/ExcelGridFieldExportButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function handleExport($gridField, $request = null)
$func = $this->afterExportCallback;
$func();
}

header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
Expand Down Expand Up @@ -288,6 +288,8 @@ public function generateExportFileData($gridField)
return $excel;
}

$exportFormat = ExcelImportExport::config()->export_format;

foreach ($list as $item) {
if ($this->checkCanView) {
$canView = true;
Expand Down Expand Up @@ -318,7 +320,12 @@ public function generateExportFileData($gridField)
// Support only one param for now
$value = $item->$func($params[0]);
} else {
$value = $gridField->getDataFieldValue($item, $columnSource);
if (array_key_exists($columnSource, $exportFormat)) {
$format = $exportFormat[$columnSource];
$value = $item->dbObject($columnSource)->$format();
} else {
$value = $gridField->getDataFieldValue($item, $columnSource);
}
}
} else {
// We can also use a simple dot notation
Expand Down

0 comments on commit 834b05e

Please sign in to comment.