KoolReport's Forum

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

How to access the data from datasource in the setup() function? #2176

Closed Chris Sideris opened this topic on on Jun 30, 2021 - 2 comments

Chris Sideris commented on Jun 30, 2021

Hi, I am creating a datasource and then trying to access its data within the setup() function but the data comes out to be NULL even though there is data when I try to dump out the data items in the view.

This is my code:

            $this->src("test")
                 ->query($query)
                 ->pipe($this->dataStore("testStore"));

            $data_items = $this->dataStore("testStore")->data(); 
            print_r($data_items); // this comes out to be an empty Array
cfsinc commented on Jul 1, 2021

Have you tried the following?

$data_items = $this->src("test")->query($query)->pipe($this->dataStore("testStore"));

print_r($data_items);
Sebastian Morales commented on Jul 1, 2021

Normally in the setup function only setup information is saved and no data is to be processed yet. But there's a method called requestDataSending which would pull data right at once to datastores like this:

 $this->src("test")
                 ->query($query)
                 ->pipe($this->dataStore("testStore"))
 ->requestDataSending(); //populate data to the datastore

print_r($this->dataStore("testStore")->data()); //datastore's data is not empty now

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