File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use Illuminate \Support \Facades \Bus ;
6
6
use Illuminate \Support \Facades \Storage ;
7
+ use Illuminate \Support \Str ;
7
8
use Livewire \Component ;
8
9
9
10
class ExportButtonComponent extends Component
@@ -47,16 +48,31 @@ public function updateExportProgress()
47
48
48
49
public function downloadExport ()
49
50
{
50
- return Storage::download ('exports/ ' .$ this ->batchJobId .'. ' .$ this ->getType (), $ this ->filename );
51
+ return Storage::download ('exports/ ' .$ this ->batchJobId .'. ' .$ this ->getType (), $ this ->getFilename () );
51
52
}
52
53
53
54
public function render ()
54
55
{
55
- return view ('datatables-export::export-button ' );
56
+ return view ('datatables-export::export-button ' , [
57
+ 'fileType ' => $ this ->getType ()
58
+ ]);
56
59
}
57
60
58
61
protected function getType (): string
59
62
{
63
+ if (Str::endsWith ($ this ->filename , ['csv ' , 'xlsx ' ])) {
64
+ return pathinfo ($ this ->filename , PATHINFO_EXTENSION );
65
+ }
66
+
60
67
return $ this ->type == 'csv ' ? 'csv ' : 'xlsx ' ;
61
68
}
69
+
70
+ protected function getFilename ()
71
+ {
72
+ if (Str::endsWith ($ this ->filename , ['csv ' , 'xlsx ' ])) {
73
+ return $ this ->filename ;
74
+ }
75
+
76
+ return null ;
77
+ }
62
78
}
Original file line number Diff line number Diff line change 3
3
x-on:submit.prevent ="
4
4
$refs.exportBtn.disabled = true;
5
5
var url = window._buildUrl(LaravelDataTables['{{ $tableId } } '], 'exportQueue');
6
- $.get(url + '&exportType={{ $type } } ').then(function(exportId) {
6
+ $.get(url + '&exportType={{ $fileType } } ').then(function(exportId) {
7
7
$wire.export(exportId)
8
8
}).catch(function(error) {
9
9
$wire.exportFinished = true;
You can’t perform that action at this time.
0 commit comments