KoolReport's Forum

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

Amazing Cards with datastore #1537

Closed Keith Burke opened this topic on on Jul 19, 2020 - 2 comments

Keith Burke commented on Jul 19, 2020

Hi,

Is it possible to use a Card getting it's data from a [single value] dataStore or do we have to extract data into a variable value?

I've seen the example...

Card::create(array(
    "value"=>$this->src("automaker")->query("select sum(amount) from payments"),
    "title"=>"Total Sale",
));

...But this means moving SQL from the controller to the view, something I'd rather not do. I'd much rather pass it in a datastore that just has one key->value pair. Like...

Card::create(array(
    "dataStore"=>$this->dataStore('single_two_column_row_extracted_from_sql')
    ,"columns"=>array(
			"Title"=>array(
		                "cssStyle"=>"text-align:center;font-weight: bold;color:red;"
		                )
        )
));
KoolReport commented on Jul 19, 2020

Yes, it is possible. You don't need to extract value from dataStore, rather the Card will try to access the value of first row and first column in dataStore.

Keith Burke commented on Jul 19, 2020

Amazing. It works. I should have tried it first. Thank you. For reference to others...

        Card::create(array(
            "value"=>$this->dataStore('sql_query_result'),
            "title"=>"This is a title",
            "cssClass"=>array(
                "card"=>"bg-primary",
                "title"=>"text-white",
                "value"=>"text-white"
            )
        ));
        SimpleCard::create(array(
            "value"=>$this->dataStore('sql_query_result'),
            "title"=>"This is a title",
            "cssClass"=>array(
                "icon"=>"fa fa-dollar"
            )
        ));

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
suggestion

None