KoolReport's Forum

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

Please add more widget #571

Open Cord opened this topic on on Dec 21, 2018 - 9 comments

Cord commented on Dec 21, 2018

check out: http://preview.tabler.io

Would be great if you can add widgets like these:

They are all BS4 based.

Maybe you can provide an example for visualizing simple values, I could built the widgets and contribute them on github?

KoolReport commented on Dec 21, 2018

Those widgets looks great. You may create new widget by extends the \koolreport\core\Widget and overwrite two important methods onInit() and onRender(). In the onRender() method, you call $this->template($data) to render. It automatically load the template file of widget {widgetname}.tpl.php.

Cord commented on Dec 21, 2018

would the following be the smartest way to work with single value fields?

    Number::create([
        "title" => "KPI 2",
        "dataSource" => array(
            array("value1" => "25")
        )
    ]);

(I would like to keep the dataStore approach to be able to retrieve values through the framework)

and in .tpl.php

    <?php echo $this->title; ?>:
    <?php
    foreach ($this->dataStore as $row) {
        echo $row['value1'];
    }
    ?>
KoolReport commented on Dec 21, 2018

To use the dataStore, in the onInit() methods you call

$this->useDataSource();

This simple function will handle all kinds of data source. After this function, you can get data from $this->dataStore like above.

KoolReport commented on Dec 21, 2018

Forget to answer your question, may be you do not need to use the datasource here. We only need single value to display so you may make it simple like this:

Number::create([
    "title"=>"Income",
    "value"=>5434.12,
    "prefix"=>"$",
    "suffix"=>"".
    "decimals"=>2
    "thousandSeparator"=>",",
    "decimalPoint"=>"."    
]);

The value receive number and you can feed any number there. You can use like this as well:

"value"=>$this->dataStore("orders")->sum("amount")
Cord commented on Dec 21, 2018

very nice!

so it is reusing the same dataStore, smart :)

I need to stop for this year, but will continue in january

keep on the great work!

Cord commented on Jan 7, 2019

My current solution to combine different visualisations into one report is to use html code within the *.view.php to layout the different components.

For simple numeric values I access the datastore object directly like this (instead of building a dedicated component):

<div>count: <?php echo $this->dataStore("orders")->count('*'); ?></div>

can you confirm that this is an valid approach?

Or is there a way to build complex reusable components, which utilise existing components (graphs, tables...), and can be called like this:

myComplexComponent::create([
        "dataSource" => $this->dataStore("orders")
    ]);

(which would then render a revenue number, a trendline, a trend indicator, list of latest orders etc...)

KoolReport commented on Jan 7, 2019

That's perfect approach!

Cord commented on Jan 8, 2019

the direct access in *.view.php like this

<div>count: <?php echo $this->dataStore("orders")->count('*'); ?></div>

returns 0 (however running the SQL directly works) - do I need to trigger the execution of the datastore query somewhere?

Cord commented on Jan 8, 2019

ok $this->run(); does the trick ;)

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
None yet

None