-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION/PROPOSAL] Export original field instead of computed ones #55
Comments
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. |
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.
The text was updated successfully, but these errors were encountered: