Get KoolPHP UI with 30% OFF!

Format string to replace zero with blank

Michael
Is there a format string I can use to replace cells with just a single zero with a blank? The zero cells are distracting. I only want to see non-zero values in the cells.
Posted Aug 27, 2016 Kool
Michael
For now, I'm doing the following which is working:
<?php
$htmlstring=$pivot->Render();
$newhtmlstring=str_replace("<td class='kptDataCell text-right '>0</td>","<td class='kptDataCell text-right '>&nbsp;</td>",$htmlstring);
echo $newhtmlstring;
?>
Posted Aug 27, 2016 Kool
David
Hi Michael,
One way to remove the zero cell is to filter out the zero value in your sql select query. For example:
select row_field, column_field, data_field from table where data_field != 0
Note that this only works correctly if all your data_field's values are greater than or equal to 0. Thanks!
Posted Aug 29, 2016 Kool
David
I almost forgot. There's also another way to change a field's value by overriding a pivot field's DisplayFormat method. Say you use a PivotSumField for data field, what you could do in your case is like:
class MyPivotSumField extends PivotSumField {
  function DisplayFormat($_value) {
    if ($_value == 0)
      return "";
    else
      return parent::DisplayFormat($_value );    
  }
}

Thanks!
Posted Aug 29, 2016 Kool -
Michael
Yes, that worked perfectly! I didn't even know you could extend a class like that! I'm sure this technique is much more efficient that my replacing a zero string with &nbsp;
Thanks for the PHP lesson!!!
Mike
Posted Aug 29, 2016 Kool -