KoolReport's Forum

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

DrillDown and Dashboard #2791

Closed GHSix opened this topic on on Aug 11, 2022 - 7 comments

GHSix commented on Aug 11, 2022

Now, after a couple of weeks of coding and forum questions, I guess I'm getting my dashboard project in a good and functional state, soom I'll focus my attention only to SQLs and Tables to get my data on the graphs. Thank you guys for that.

But now, for last, I went to try out the DrillDown package and got amazed how it seems off the dashboard way, at least in the samples. It may look noob of me, but I could not find how to communicate with the dashboard from within the koolreport inside a KWidget. For example, I tried to:

Level::create()
                ->widget(
                    KWidget::create()
                    ->use(\koolreport\widgets\google\ColumnChart::class)
                    ->dataSource(function($params, $scope) {
                        return $this->dashboard()->getSharedData()
                            ->run()
                            ->process(\koolreport\processes\Group::process([
                                'by' => 'dt',
                                'sum' => 'qtd_av',
                                'sum' => 'val_av'
                            ]));
...

But, besides $this->dashboard() exists, it's null.

So I got 3 questions.

  1. Is it possible to passing a Dashboard widget directly to Level widget or to KWidget, the way we pass it to a Row or Panel?
  2. If 1 is not possible, how to communicate to and from koolreport chart and dashboard?
  3. If 1 is not possible, there is a way to, using the Dahboard KPI Products Demo as example, click on the chart and, instead of just reload the table, to get the action function to replace the table with another table or chart widget so we can mimic the drill down?
KoolReport commented on Aug 11, 2022

Yes, agree that it is quite off the dashboard way. It is because we utilize the DrillDown package and the package was released long before Dashboard was designed. So we tried to make a bridge to bring DrillDown to Dashboard. Come to your question, you do this:

protected function levels()
{
    $dashboard = $this->dashboard();

    return [
        Level::create()
                ->widget(
                    KWidget::create()
                    ->use(\koolreport\widgets\google\ColumnChart::class)
                    ->dataSource(function($params, $scope) use ($dashboard) {
                        return $dashboard->getSharedData()
                            ->run()
                            ->process(\koolreport\processes\Group::process([
                                'by' => 'dt',
                                'sum' => 'qtd_av',
                                'sum' => 'val_av'
                            ]));
                ...
}

We use the use ($dashboard) in the anonymous function.

Hope that helps.

GHSix commented on Aug 11, 2022

I see. Thank you.

And for the 3, it is really not possible? Would be cool to be able to use the boards I already have built instead of have to rewrite them to fit DrillDown.

KoolReport commented on Aug 11, 2022

For the 3, it is possible too. Each widget like table or chart has property hidden() that you can use to hide or show a widget. So on action of a widget, you can do:

$this->hidden(true)->update();
$this->sibing("other-widget")->hidden(false)->update();

Let me know if it works for you.

GHSix commented on Aug 11, 2022

For the 2, it's given:

Message: Function name must be a string
Line: return $dashboard->getSharedData()

For 3, it seems like a good idea only if Dashboard have code in place to not run the queries for hidden widgets, otherwise it could be problematic to run all the queries for all hidden widgets at the same time. Does hidden widgets run their queries?

If so, since you let me believe it is not possible to explicity replace a widget, I guess the next good option would be something like:

protected function widgets()
    {
        $sub = [];

        switch ($level) {
            case 1: 
                $sub[] = ColumnChartB::create()->lazyLoading(true);
            break;

            case 2:
                $sub[] = ColumnChartC::create()->lazyLoading(true);
            break;

            default: 
                $sub[] = ColumnChartA::create()->lazyLoading(true);
        }

        return [
            Panel::create()->sub($sub)
        ];
    }

What do you think?

GHSix commented on Aug 12, 2022

I have tested and it worked like:

$sub = ($level == 2)? '\Path\ColumnChartB' : '\Path\ColumnChartA';

Panel::create()
                ->sub([
                    $sub::create()->lazyLoading(true),
                ])

I'm just not sure if this is the best aprouch.

KoolReport commented on Aug 12, 2022

It looks very fine. I actually have not experienced this before so I guess I will perform some tests on this. Thank you for bringing a great case here.

GHSix commented on Aug 12, 2022

Nice!

Thank you.

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
solved

Dashboard