Skip to content

Commit 6e508f0

Browse files
committed
Compute export type based on filename if set.
1 parent b7c59fb commit 6e508f0

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/Livewire/ExportButtonComponent.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Facades\Bus;
66
use Illuminate\Support\Facades\Storage;
7+
use Illuminate\Support\Str;
78
use Livewire\Component;
89

910
class ExportButtonComponent extends Component
@@ -47,16 +48,31 @@ public function updateExportProgress()
4748

4849
public function downloadExport()
4950
{
50-
return Storage::download('exports/'.$this->batchJobId.'.'.$this->getType(), $this->filename);
51+
return Storage::download('exports/'.$this->batchJobId.'.'.$this->getType(), $this->getFilename());
5152
}
5253

5354
public function render()
5455
{
55-
return view('datatables-export::export-button');
56+
return view('datatables-export::export-button', [
57+
'fileType' => $this->getType()
58+
]);
5659
}
5760

5861
protected function getType(): string
5962
{
63+
if (Str::endsWith($this->filename, ['csv', 'xlsx'])) {
64+
return pathinfo($this->filename, PATHINFO_EXTENSION);
65+
}
66+
6067
return $this->type == 'csv' ? 'csv' : 'xlsx';
6168
}
69+
70+
protected function getFilename()
71+
{
72+
if (Str::endsWith($this->filename, ['csv', 'xlsx'])) {
73+
return $this->filename;
74+
}
75+
76+
return null;
77+
}
6278
}

src/resources/views/export-button.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
x-on:submit.prevent="
44
$refs.exportBtn.disabled = true;
55
var url = window._buildUrl(LaravelDataTables['{{ $tableId }}'], 'exportQueue');
6-
$.get(url + '&exportType={{$type}}').then(function(exportId) {
6+
$.get(url + '&exportType={{$fileType}}').then(function(exportId) {
77
$wire.export(exportId)
88
}).catch(function(error) {
99
$wire.exportFinished = true;

0 commit comments

Comments
 (0)