KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Export PDF on KoolReport Dashboard #3215

Closed afieq opened this topic on on Dec 21, 2023 - 6 comments

afieq commented on Dec 21, 2023

Hi,

I'm using export PDF on my dashboard and it works fine. The problem i having is when i print the dashboard, it print the whole page including the button 'Export to PDF' on my current page of dashboard. Is there a way to exclude the button from printing with my widget report?

Thanks in advance.

Regards, Afieq

KoolReport commented on Dec 24, 2023

Actually it is quite easy to do so, you do like this:

class MyDashboard extends Dashboard
{
    protected exportMode = false;

    public function exportedView()
    {
        $this->exportMode = true;
        return $this->view();
    }

    protected function content()
    {
        return [
            ...
                ($this->exportMode===false)?Button::create()->text("Export To PDF"):null,
            ...
        ];
    }

}

What above code does is when the exportedView is called, it will set the exportMode to true, then in the content of dashboard, the button export to PDF will not be created.

Let us know if it helps.

afieq commented on Dec 24, 2023

Hi KoolReport,

I tried your suggestion but it throws error 'Unexpected '='. Expected 'VariableName' on 'protected exportMode = false;'. Do i need to declare anything before using your code suggestion?

Thanks in advance.

Regards, Afieq

KoolReport commented on Dec 24, 2023

Please mkae a dollar sign on exportMode, $exportMode to be specific.

afieq commented on Dec 24, 2023

Hi KoolReport,

I tried and the code work fine, but my export pdf still include the button. Did i miss something on my codes?

class HomeBoard extends Dashboard
{
    protected $exportMode = false;

    public function exportedView()
    {
        $this->exportMode = true;
        return $this->view();
    }

    protected function onInit()
    {
        $this->default(true)
            ->title("Home")
            ->hidden(false)
            ->icon("fa fa-home")
            ->updateEffect("fade")
            ->pdfExportable(true); //Turn on pdf exportable for dashboard;
    }
    protected function content()
    {
        return [
            ($this->exportMode===false)?Button::create()->text("Export to PDF")->onClick(
                Client::showLoader() .
                Client::dashboard($this)->exportToPDF("Dashboard")
            ):null,
    ...
        ],
    }
}

Regards, Afieq

KoolReport commented on Dec 25, 2023

I see, let try another way:

class MyDashboard extends Dashboard
{
    public function exportedView()
    {
        $this->widget("exportButton")->hidden(true);
        return $this->view();
    }

    protected function content()
    {
        return [
            ...
                Button::create("exportButton")->text("Export To PDF")
            ...
        ];
    }

}

This way you create the button like normal, but give it a name, in this case is "exportButton" then in the exportedView function, you hide the button.

Please let me know.

afieq commented on Dec 28, 2023

Hi KoolReport,

I tried your new suggestion and it works like a charm. The PDF export now have exclude the Button from the printing. Thank you for your help.

Regards, Afieq

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

Export