KoolReport's Forum

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

How to extends KWidget from Card #2696

Closed fiuncho opened this topic on on May 25, 2022 - 5 comments

fiuncho commented on May 25, 2022

Dear team

Using Dashboard.

I have this widget extended from KWidget,I was following the documentation, but the result is a card with a "0" value.

How can I set a value and title to this?.

And If I want to get the value from database using params, for example: year, month and costumer?

<?php

namespace demo\instrument;
use demo\InstrumentDB;

use \koolreport\dashboard\widgets\KWidget;

//use \koolreport\dashboard\widgets\SimpleCard;
//use koolreport\chartjs\SimpleCard

class IntrumentSales extends KWidget
{
  
    //protected function onInit()
    protected function onInit()
    {
        $this->use(\koolreport\widgets\koolphp\Card::class)::create(array(
                "title"=>"Month Sale",
                "value"=>11249,
                "baseValue"=>9230,
                "format"=>array(
                    "value"=>array(
                        "prefix"=>"$"
                    )
                )
        ));
                               
    }
   
}

Thanks for your support

KoolReport commented on May 25, 2022

You do:

class IntrumentSales extends KWidget
{
  
    //protected function onInit()
    protected function onInit()
    {
        $this->use(\koolreport\widgets\koolphp\Card::class)
                ->settings(array(
                    "title"=>"Month Sale",
                    "value"=>11249,
                    "baseValue"=>9230,
                    "format"=>array(
                        "value"=>array(
                            "prefix"=>"$"
                        )
                    )
        ));
                               
    }
   
}
fiuncho commented on May 26, 2022

yesss!!!

run!!!

Thanks for your support!!! :)

John commented on Aug 20, 2023

How did you get the values from the database?

KoolReport commented on Aug 20, 2023

You can do something like this:

...
"value"=>AutoMaker::table("orders")->sum("amount")->run()->getScalar(),
...

run() will perform query data and then getScalar() will take the value at the first row and first column.

John commented on Aug 20, 2023

Great, thanks!

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
solved

None