Open skoyah opened 5 years ago
Currently we can't make the distinction between that. The goal of the package is to exactly export what is shown in the index view.
I'm planning to look into a different way of selecting which fields should be in an export (something like ->onlyOnIndex
but than exceptInExport
and onlyInImport
- Perhaps even a displayForExport()
). Not sure if it's possible, but it's something I have on my roadmap to look into.
Thanks for the feedback. I came up with a temporary solution. For anyone that might encounter the same thing in the near future:
This way, by making the first email field 100% computed, the second field will the one being exported even when hidden.
Thanks for the feedback. I came up with a temporary solution. For anyone that might encounter the same thing in the near future:
This way, by making the first email field 100% computed, the second field will the one being exported even when hidden.
Unfortunately this trick does not work anymore :-(
This feature would be a great addition if possible.
is there any solution for this?
I just duplicate the fields and use this macros to decide when to show/use each:
Field::macro('onlyInExport', function () {
// LaravelNovaExcel only uses fields that are visible in the index
return $this
// First hide it everywhere except on indexes
->onlyOnIndex()
// Then decide when to show it when loaded an index
->showOnIndex(function (Request $request) {
return $request instanceof \Maatwebsite\LaravelNovaExcel\Requests\ExportResourceActionRequest;
});
});
Field::macro('showOnExport', function () {
// LaravelNovaExcel only uses fields that are visible in the index
return $this
// In this case we don't care what other places the field is show
->showOnIndex(function (Request $request) {
return $request instanceof \Maatwebsite\LaravelNovaExcel\Requests\ExportResourceActionRequest;
});
});
I've actually been procrastinating on making a PR with this 2 macros, maybe someone can go ahead and do it. These have been very useful for me.
Versions
Description
Resource index page displays a computed field from the original field. In this case, was adding an anchor tag to the email field using the Nova's method
displayUsing()
.Steps to Reproduce
Expected behavior:
Exporting to excel should use the original field instead of the computed one.
Actual behavior:
Exported field is exported with the computed format (eg. html tag)
Additional Information
Since it is usefull in some cases to export the computed fields, maybe we could have an option to toggle this behaviour either to a single or multiple columns.