Skip to content

Commit 6a8a2c5

Browse files
authored
Merge pull request #13 from iYogesharma/3.x
Export Handler
2 parents be5c2c8 + e744046 commit 6a8a2c5

File tree

9 files changed

+34
-404
lines changed

9 files changed

+34
-404
lines changed

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"minimum-stability": "dev",
1616
"require": {
1717
"php": ">=7.0.0",
18-
"laravel/framework": "5.*|6.*|7.*|8.*"
18+
"laravel/framework": "5.*|6.*|7.*|8.*",
19+
"iyogesharma/export": "^1.0",
20+
"ext-json": "*"
1921
},
2022
"require-dev": {
2123
"phpunit/phpunit": "^6.4|^9.0",
@@ -51,4 +53,4 @@
5153
"dev-master": "3.x-dev"
5254
}
5355
}
54-
}
56+
}

src/AbstractDatatable.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ public function __construct()
9494
*/
9595
public function datatable($source, $json = false)
9696
{
97-
// dd($source);
97+
if( $this->request->isForExport() )
98+
{
99+
$class = "\\YS\\Export\\".$this->request->extension();
100+
return (new $class( $source ))->response();
101+
}
98102
// Set properties of class and initialize datatable
99103
$this->boot($source);
100104

@@ -110,6 +114,11 @@ public function datatable($source, $json = false)
110114
*/
111115
public function makeDatatable($source)
112116
{
117+
if( $this->request->isForExport() )
118+
{
119+
$class = "\\YS\\Export\\".$this->request->extension();
120+
return (new $class( $source ))->response();
121+
}
113122
// Set properties of class and initialize datatable
114123
$this->boot($source);
115124

@@ -137,7 +146,6 @@ protected function boot($source)
137146

138147
/** Set properties of instance of class*/
139148
$this->setQuery($source);
140-
141149
}
142150

143151
/**
@@ -406,7 +414,6 @@ public function remove($column)
406414
foreach ($this->result as $r) {
407415
unset($r->$c);
408416
}
409-
410417
}
411418
} else {
412419
foreach ($this->result as $r) {
@@ -463,6 +470,4 @@ public function getQuery()
463470
{
464471
return $this->query;
465472
}
466-
467-
468473
}

src/DatatableRequest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,23 @@ public function getColumns()
9797
{
9898
return $this->request->input('columns');
9999
}
100+
101+
/**
102+
* Whether request is for file export
103+
* @return bool
104+
*/
105+
public function isForExport()
106+
{
107+
return $this->request->input('export') == true;
108+
}
109+
110+
/**
111+
* desire extension for exported file
112+
* @return string
113+
*/
114+
public function extension()
115+
{
116+
return ucfirst($this->request->input('ext') ?? 'Xls');
117+
}
100118

101-
}
119+
}

src/Export/Csv.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)