KoolReport's Forum

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

DataStore is empty #2508

Open Richb201 opened this topic on on Dec 25, 2021 - 4 comments

Richb201 commented on Dec 25, 2021

In my view file I am creating a table like this. Sometimes there are no qualified_dollars and instead of displaying an error I'd like to show "sorry, no data". I found this function in the docs

if($this->dataStore('customer')->isEmpty())
{
    echo "No data available!";
}

But I doubt that I can use this in the middle of a create(). How can I just show no data available and escape the error?

Table::create(array(
        "dataStore"=>$this->dataStore("BPlt_BC")->filter("taxyear","=",$_SESSION['last_TY']) ->filter("qualified_dollars",">",0),
        
        "showFooter"=>false,
        "grouping"=>array(
            "item"=>array(
                "calculate"=>array(
                    "{sumAmount}"=>array("sum","dollarsPerBC"),
                ),
                "cssStyle"=>"text-align:right",
                "bottom"=>"<td colspan='6 style='text-align: right'><b>Total qualified RESEARCHER wages for : {item}</b></td><td style='text-align: right'><b>{sumAmount}</b></td><br>",

            ),
        ),

        "showFooter"=>"bottom",
        "columns"=>array(
            "item"=>array("label"=>"Business Component"),
            "employee"),

        "cssClass"=>array(
            "table"=>"table table-bordered",
            "tr"=>"row-css-class",
            "th"=>"header-css-class",
            "td"=>"cell-css-class",
            "tf"=>"footer-cell-css-class",
        )
    )
KoolReport commented on Dec 25, 2021

You can do:

<?php

$store = $this->dataStore("BPlt_BC")->filter("taxyear","=",$_SESSION['last_TY']) ->filter("qualified_dollars",">",0);

if($store->isEmpty())
{
    echo "no data";
} else {
    Table::create([
        "dataStore"=>$store,
        ...
    ]);
}

?>
Richb201 commented on Dec 26, 2021

Got it. Thanks.

Richb201 commented on Dec 27, 2021

Rather than it being empty, it actually just has "zero rows". So when I try to run $store=$this->dataStore("BPlt_BC")->filter("taxyear","=",$_SESSION['last_TY']) ->filter("qualified_dollars",">",0); I get the error qualified_dollars does not exist. How can I check for no rows? before running this filter and loading $store?

Sebastian Morales commented on Dec 28, 2021

The column key does not exist error is most likely because of no meta data for that column rather than zero data rows.

Anyway, I think $datastore->isEmpty() is equivalent to zero data rows as well. So just check for $datastore->isEmpty() before filtering so that no errors occur even if there's no meta data.

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

None