KoolReport's Forum

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

Dashboard array datasource #2805

Open Amr opened this topic on on Aug 21, 2022 - 3 comments

Amr commented on Aug 21, 2022

Dear All Datasource of my dashboard came form API converted into array, no problem with that, the question is what is the best way to make processing on this data in the array (group, sort, ...etc) before using it in widgets. thx for help

Sebastian Morales commented on Aug 22, 2022

You can process your dashboard widget's data in method dataSource like this:

    protected function dataSource()
    {
        return CSV::file("data/customer_product_dollarsales2.csv")
                ->fieldSeparator(";")
                ->select('customerName', 'productLine', 'productName','dollar_sales')
                ->where('customerName','<','Am')
                ->where('orderYear','>',2003)
                ->run() //After run(), we will get DataStore, we continue to process data with ColumnMeta and Pivot
                ->process(
                    // Add processes here
                    \koolreport\processes\ColumnMeta::process([
                        ...
                    ])
                    ->pipe(new \koolreport\processes\Map([
                        ...
                    ]))                    

                );
    } 
Amr commented on Aug 22, 2022

thanks Sebastian for your comment, actually my question is that when i apply run() to data in array it doesn't work this is my code:

return $this->dashboard()->getapiData("subserv")->run()

it gives me the following message:

Message: Call to a member function run() on array Line: 32

KoolReport commented on Aug 22, 2022

Well, you convert array data into DataStore and then you can process data.

protected function dataSource()
{
    $data = $this->dashboard()->getapiData("subserv");
    return (new \koolreport\core\DataStore($data))->process(
                    // Add processes here
                    \koolreport\processes\ColumnMeta::process([
                        ...
                    ])
                    ->pipe(new \koolreport\processes\Map([
                        ...
                    ]))     
    );
}

Let us know if it works.

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

Dashboard