MedicOneSystems / livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS
https://livewire-datatables.com/
MIT License
1.19k stars 258 forks source link

Export functionality #446

Open gray-penguin opened 2 years ago

gray-penguin commented 2 years ago

Hide/Show Columns makes no changes to the exported columns. Am I missing something?

gray-penguin commented 2 years ago

Going off a suggestion in another issue, I used this in my controller:

public function getExportResultsSet() { return $this->mapCallbacks( $this->getQuery()->when(count($this->selected), function ($query) { return $query->havingRaw('checkbox_attribute IN (' . implode(',', $this->selected) . ')'); })->get(), true )->map(function ($item) { return collect($this->columns())->reject(function ($value, $key) { // changed below to have all table columns included in the export even if it is hidden //return $value->preventExport == true || $value->hidden == true; return $value->preventExport == true; })->mapWithKeys(function ($value, $key) use ($item) { return [$value->label ?? $value->name => $item->{$value->name}]; })->all(); }); }

muhirza commented 1 year ago

I also need this answer. Do you manage to know it?