KoolReport's Forum

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

Filter on datastore is not working! #2144

Open Kay opened this topic on on Jun 15, 2021 - 8 comments

Kay commented on Jun 15, 2021
Table::create(array(
    "dataSource"=>$report->dataStore("data")->filter("column","=",10)
));

the above code gives an undefined index error.

Table::create(array(
     "dataSource"=>$report->dataStore("data")->filter(function($row){
        return $row["column"] == 10;
    })
));

However on using this method it gives no data available in table.

What could possibly be the reason? Thank you.

Sebastian Morales commented on Jun 15, 2021

Pls print out your datastore's data to see if column "column" exists:

    print_r($report->dataStore("data")->data());

Pls remember that $report->dataStore() only returns data after $report->run() is called. Tks,

Kay commented on Jun 15, 2021

Yes it does exist.

Table::create(array(
    "dataSource"=>$report->dataStore("data")
));

Displays all the data fetched from the database.

Sebastian Morales commented on Jun 15, 2021

Then print out the datastore's data to check if column name "column" exists. Tks,

Kay commented on Jun 15, 2021

On printing datastore's data i get

Array ( ) 

but if I put this code

Table::create(array(
    "dataSource"=>$report->dataStore("data")
));

before this

print_r($report->dataStore("data")->data());

i get the data from both the codes

Sebastian Morales commented on Jun 16, 2021

Did you call $report->run() before using its datastore? The "dataSouce' property probably called some function that populated the datastore but it doesn't always work. We must run a report to make sure to populate its datastores. Rgds,

Kay commented on Jun 16, 2021

After calling $report->run() it works. Thanks! But in all of my previous reports I didn't call the above function before populating data from datastores, does that mean I have to call this function on each and every report?

Sebastian Morales commented on Jun 16, 2021

Yes, Kay. It's standard practice to call $report->run() for every report. In some special case some widgets can call a report's request data sending method automatically but we shouldn't always expect that. Tks,

Kay commented on Jun 16, 2021

Okay thank you so much for your help.

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
solved

Laravel