Skip to content

Commit

Permalink
1. adding 30 default filter
Browse files Browse the repository at this point in the history
2. adding full collection export excel
  • Loading branch information
perladarianny15 committed Aug 2, 2021
1 parent 45659ae commit 2a8826f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 27 deletions.
2 changes: 2 additions & 0 deletions resources/views/bootstrap/main.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
10
@elseif($perPage == '20')
20
@elseif($perPage == '30')
30
@elseif($perPage == '100')
100
@endif
Expand Down
64 changes: 39 additions & 25 deletions src/Classes/ExportExcelClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,66 @@

class ExportExcelClass implements FromCollection, WithHeadings
{
private $type;
private $collection;
private $headings;

public function __construct($collection_to_export, $collection_headings) {
public function __construct($type, $collection_to_export, $collection_headings = null) {

$this->type = $type;
$this->collection = $collection_to_export;
$this->headings = $collection_headings;
}

public function collection()
{
$subCollection = $this->collection->map(function ($user) {
$result = [];
if($this->type == 'full_collection') {
return $this->collection;

foreach ($this->headings as $itemKey => $itemValue)
{
$collection = Str::of($itemKey)->explode('.');
$val = $user;
}elseif($this->type == 'merged_collection')
{
$subCollection = $this->collection->map(function ($user) {
$result = [];

foreach ($this->headings as $itemKey => $itemValue) {
$collection = Str::of($itemKey)->explode('.');
$val = $user;

foreach ($collection as $rel) {
if ($val === null) {
break;
foreach ($collection as $rel) {
if ($val === null) {
break;
}
$val = optional($val)->$rel;
$result[$itemKey] = $val;
}
$val = optional($val)->$rel;
$result[$itemKey] = $val;
}

}
return collect($result)
->all();
});
}
return collect($result)
->all();
});

return $subCollection;
return $subCollection;
}

}

public function headings(): array
{
$headingsResult = [];
foreach ($this->headings as $items)
if($this->type == 'full_collection')
{
if($items['columnName'] !== null)
{
$headingsResult[] = $items['columnName'];
return array_keys($this->collection->first()->toArray());

}elseif ($this->type == 'merged_collection') {


$headingsResult = [];
foreach ($this->headings as $items) {
if ($items['columnName'] !== null) {
$headingsResult[] = $items['columnName'];
}
}
}

return $headingsResult;
return $headingsResult;
}
}
}
6 changes: 4 additions & 2 deletions src/Http/Livewire/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Main extends Component

public function mount($tableArr = null, $query = null)
{
$this->perPage = 10;
$this->perPage = 30;
$this->tableStruct();
$this->getFilterFromSession();
}
Expand Down Expand Up @@ -243,7 +243,9 @@ public function downloadExcel()
{
$query = $this->queryStruct();

return Excel::download(new ExportExcelClass($query, $this->Data),now()->toDateString() . ' excel.xlsx');
//Full Collection

return Excel::download(new ExportExcelClass('full_collection', $query),now()->toDateString() . ' excel.xlsx');
}

public function saveFilterToSession()
Expand Down

0 comments on commit 2a8826f

Please sign in to comment.