KoolReport's Forum

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

How to get column name on table cell click #1555

Open Sergio opened this topic on on Aug 10, 2020 - 4 comments

Sergio commented on Aug 10, 2020

Hello. i am currently having a problem where i need to get the column name upon table cell click. I know i can achieve this by FormatValue, but i can only get the $value and $row data but no column name. is there any other thing i can use for this?

Thankyou

David Winterburn commented on Aug 11, 2020

Hi Sergio,

We will add the column name parameters to Table's and DataTables' formatValue function in the next release of KoolReport. In the meantime, you could achieve this by modify the widgets' code a bit. For example, please open the file koolreport/core/src/widgets/koolphp/Table.tpl.php and replace the following string:

<?php echo Table::formatValue($value, $meta["columns"][$cKey], $row);?>

with:

<?php echo Table::formatValue($value, $meta["columns"][$cKey], $row, $cKey);?>

Then open the file koolreport/core/src/widgets/koolphp/Table.php and replace:

    public static function formatValue($value, $format, $row = null)
    {
        $formatValue = Utility::get($format, "formatValue", null);

        if (is_string($formatValue)) {
            eval('$fv="' . str_replace('@value', '$value', $formatValue) . '";');
            return $fv;
        } else if (is_callable($formatValue)) {
            return $formatValue($value, $row);
        } else {
            return Utility::format($value, $format);
        }
    } 

with:

    public static function formatValue($value, $format, $row = null, $cKey)
    {
        $formatValue = Utility::get($format, "formatValue", null);

        if (is_string($formatValue)) {
            eval('$fv="' . str_replace('@value', '$value', $formatValue) . '";');
            return $fv;
        } else if (is_callable($formatValue)) {
            return $formatValue($value, $row, $cKey);
        } else {
            return Utility::format($value, $format);
        }
    }

Finally change the formatValue function in your report to include $cKey parameter. Let us know if you have any issue. Thanks!

Sergio commented on Aug 11, 2020

Hey David, thanks for replying. I tried what you suggested, but after i changed them i get this following error :

It seems like its having conflict with this code in Line 43 of Table.tpl.php : $footerValue = Table::formatValue($this->dataStore->$method($cKey), $meta["columns"][$cKey]);

Maybe a new parameter have to be passed in this code as well ?

By the way, i am implementing the new $cKey parameter in this way in the formatValue function :

Let me know what to do for this. Thankyou!

David Winterburn commented on Aug 11, 2020

Please replace:

public static function formatValue($value, $format, $row = null, $cKey)

with:

public static function formatValue($value, $format, $row = null, $cKey = null)

Thanks!

Sergio commented on Aug 11, 2020

Hello David, Everything is working now. Thankyou for fast support.

Cheers!

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