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

Add ability to have different exportConversions for PDF #843

Closed
pappfer opened this issue Oct 23, 2018 · 2 comments
Closed

Add ability to have different exportConversions for PDF #843

pappfer opened this issue Oct 23, 2018 · 2 comments

Comments

@pappfer
Copy link
Contributor

pappfer commented Oct 23, 2018

Now we have an option to convert some text to another with using exportConversions option. However we can only have the same text for all data types, we can't have different text for example for Excel and for PDF files.

I would like the ability to have a 'toPdf' option inside exportConversions so I could display a HTML entity image in a PDF file, while it is not possible in an Excel one.

Scenario:
I have a lot of BooleanColumns in my grid and I don't want to replace them with "Yes/No" or "Active/Incative" texts, I would rather display a tick or a cross icon in the PDF.

Example:

$this->exportConversions = [
    [
        'from' => BooleanColumn::$defaultTrueIcon,
        'to' => Yii::t('app', 'Yes'),
        'toPdf' => '✓'
    ],
    [
        'from' => BooleanColumn::$defaultFalseIcon,
        'to' => Yii::t('app', 'No'),
        'toPdf' => '✗'
    ],
    [
        'from' => Yii::$app->formatter->nullDisplay,
        'to' => '-',
    ],
],

I already wrote the code for it and it works just fine. For Excel it will print "Yes/No" while for PDF is shows icons. I'm submitting a pull request.

@kartik-v
Copy link
Owner

Thanks. I had a look at your PR - I feel there is a better way to configure this. Will update over this.

@kartik-v
Copy link
Owner

kartik-v commented Nov 3, 2018

Enhancement pushed.

You can now override the export conversions for specific types by setting one or both of from_<exptype> and to_<exptype> - for example:

$this->exportConversions = [
    [
        'from' => BooleanColumn::$defaultTrueIcon,
        'to' => Yii::t('app', 'Yes'),
        //'from_pdf' => 'something else', // if you need to set something like this
        'to_pdf' => '&#10003;'
    ],
    [
        'from' => BooleanColumn::$defaultFalseIcon,
        'to' => Yii::t('app', 'No'),
        'to_pdf' => '&#10007;'
    ],
    [
        'from' => Yii::$app->formatter->nullDisplay,
        'to' => '-',
        'from_xls' => 'something only for excel',
        'to_xls' => 'something replaced only for excel',
    ],
],

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

No branches or pull requests

2 participants