Skip to content
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

Open
skoyah opened this issue Jun 28, 2019 · 6 comments
Open

[QUESTION/PROPOSAL] Export original field instead of computed ones #55

skoyah opened this issue Jun 28, 2019 · 6 comments

Comments

@skoyah
Copy link

skoyah commented Jun 28, 2019

  • [X ] Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Nova Excel.
  • [X ] Checked that your issue isn't already filed.
  • [ X] Checked if no PR was submitted that fixes this problem.

Versions

  • PHP version: 7.3
  • Laravel version: 5.8.23
  • Nova version: 2.0.4
  • Package version: Laravel Nova Excel 1.1

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.

@patrickbrouwers
Copy link
Member

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.

@skoyah
Copy link
Author

skoyah commented Jun 28, 2019

Thanks for the feedback. I came up with a temporary solution. For anyone that might encounter the same thing in the near future:

Screenshot 2019-06-28 at 15 41 06

This way, by making the first email field 100% computed, the second field will the one being exported even when hidden.

@potsky
Copy link

potsky commented Jan 22, 2020

Thanks for the feedback. I came up with a temporary solution. For anyone that might encounter the same thing in the near future:

Screenshot 2019-06-28 at 15 41 06

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 :-(

@roarkmccolgan
Copy link

This feature would be a great addition if possible.

@techguydev
Copy link

is there any solution for this?

@fgilio
Copy link

fgilio commented Jul 6, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants