KoolReport's Forum

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

Blank when zero? #96

Open zenon opened this topic on on Aug 28, 2017 - 16 comments

zenon commented on Aug 28, 2017

Hi,

I want to show blank in the report if the value is zero. Could this be done with KoolReport?

Appreciate your help.

Thanks.

KoolReport commented on Aug 28, 2017

You may use the formatValue settings in Table:

Table::create(array(
    "columns"=>array(
        "sale"=>array(
            "formatValue"=>function($value)
            {
                 if($value==0) return "";
                 return $value;
            }
        )
    )
))
zenon commented on Aug 28, 2017

What if the row consists of multiple lines? How to do it?

I have tried the above but not working.

Thanks.

KoolReport commented on Aug 28, 2017

So you have to detect the 0 value right from the CalculatedColumn. If the value is 0 then you return empty string instead.

zenon commented on Aug 28, 2017

Could you please show me how to do this?

Currently my code is as below

->pipe(new CalculatedColumn(array( 
            "2"=>array(
                "exp"=>function($data){
                    return $data["amount"]."<br/>".$data["target"]."<br/>".number_format($data["a"],1)."%"."<br/>"."<br/>".number_format($data["qty"],0)."<br/>".number_format($data["l_qty"],0)."<br/>".number_format($data["b"],1)."%";
                },
                "type"=>"string",
            ),
)))

What should I do for all the lines where when each value is zero, then show blank.

Thanks a lot.

KoolReport commented on Aug 28, 2017

You do:

if($data["amount"]==0)
{
    return "";
}
else
{
    return $data["amount"]."<br/>".$data["target"]."<br/>".number_format($data["a"],1)."%"."<br/>"."<br/>".number_format($data["qty"],0)."<br/>".number_format($data["l_qty"],0)."<br/>".number_format($data["b"],1)."%";
}
zenon commented on Aug 28, 2017

How about if amount, target, a, qty, l_qty, and b zero, then blank?

KoolReport commented on Aug 28, 2017

What I am trying to show you is how to use condition to generate blank output. You can apply the same method to build you own condition on your parameters and generate output accordingly. For this I could not do it for you.

zenon commented on Aug 28, 2017

Sorry my meaning is if the result from this ,

->pipe(new CalculatedColumn(array( 
            "2"=>array(
                "exp"=>function($data){
                    return $data["amount"]."<br/>".$data["target"]."<br/>".number_format($data["a"],1)."%"."<br/>"."<br/>".number_format($data["qty"],0)."<br/>".number_format($data["l_qty"],0)."<br/>".number_format($data["b"],1)."%";
                },
                "type"=>"string",
            ),
)))

if any of the value is zero, then only blank that zero value. If other value is not zero, then it shouldn't be blank.

KoolReport commented on Aug 28, 2017

That is easy:

...=>function($data)
{
$result = "";
if($data["amount"]!=0)
{
    $result.=$data["amount"]."<br/>";
}

if($data["qty"]!=0)
{
    $result.=$data["qty"]."<br/>";
}
...

return $result;
}
zenon commented on Aug 28, 2017

I have tried this. It is ok but the blank value will be overwritten by the non-zero value.

From Table 1, the zero value will be blank, like in Table 3. But after I follow your guidance, I get just like Table 2.

Appreciate your help.

Thanks.

KoolReport commented on Aug 28, 2017

There must be something else wrong since the row B( for example ) has value 0, the calculated result can be 2 as show in table 2

zenon commented on Aug 29, 2017

The value 2 should be in row C. But when the row B is blank, the value 2 from row C will move upwards to row B. As long as the value before is blank, the non-zero value will move upwards.

KoolReport commented on Aug 29, 2017

Is it possible that you can share the page so I can have a look. or you can replicate the issue in a small scale and send over to us.

zenon commented on Aug 29, 2017

Im sorry, you mean send to you the codes or the output?

KoolReport commented on Aug 29, 2017

Please send me the code to support@koolreport.com, I will have a look at the code, hope I can spot out something

zenon commented on Aug 29, 2017

I have just send the code to you. Hopefully there is good news from your end.

Thanks a lot.

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