KoolReport's Forum

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

Category Metric Label #2779

Closed GHSix opened this topic on on Aug 2, 2022 - 8 comments

GHSix commented on Aug 2, 2022

Is it possible to change Category labels at PHP level?

I tried to:

use \koolreport\dashboard\metrics\Category;
...
protected function fields()
    {
        return [
            $this->group(
                Text::create("productLine")->customRender(function($val) {
                    return ($val == "Something")? "Stuff" : $val;
                })
            )->showTop(3)
            ->andShowOthers("Others"),
            $this->sum(Number::create("quantityInStock"))
        ];
    }

but didn´t work.

Also, whats the difference between customRender and formatUsing?

KoolReport commented on Aug 3, 2022

It seems to me the Category has not yet supported customizing the value and I believe it should. The alternative solutions are changing from dataSource

protected function dataSource()
{
    return AutoMaker::table("products")->select("productLine","quantityInStock")
                ->run()
                ->process(\koolreport\processes\Custom::process(function($row){
                    if ($row["productLine"] == "Something") $row["productLine"] = "something else";
                    return $row;
                }));
}

Hope that helps.

KoolReport commented on Aug 3, 2022

The customRender is stronger than formatUsing, the customRender can overwrite all default html of a field, while formatUsing can make additional html to default html of a field.

GHSix commented on Aug 3, 2022

It seems to work for all widgets, including Category, but Trend and Value that will show as

Message: Trying to access array offset on value of type null
Line: 62
File: /www/dev/koolreport/vendor/koolreport/dashboard/metrics/Value.php
Message: Trying to access array offset on value of type null
Line: 145
File: /www/dev/koolreport/vendor/koolreport/dashboard/metrics/Trend.php

As soon as I add ->run() it will break Trend and Value.

Why would I do that for this widgets that will not show it? Because of sharedData.

KoolReport commented on Aug 3, 2022

Let me consult the dev.team on above error message and come back to you.

KoolReport commented on Aug 4, 2022

The issue was due to no data so it cause the empty array. Our dev.team has fixed the issue and the fix will be available in next release. If you need the fix now, we can send you via email.

GHSix commented on Aug 4, 2022

No rush, I'm on dev fase, thank you.

But...

This will work with all widgets

protected function dataSource()
{
    return AutoMaker::table("products")->select("productLine","quantityInStock");
}

This will not only with Value and Trend

protected function dataSource()
{
    return AutoMaker::table("products")->select("productLine","quantityInStock")->run();
}

Since the one with ->run works on some, we can say it has data inside it, so if it does not work on Value and Trend as with it was empty, maybe something is happening in the moment this widgets parses the data, or something like that.

If there is some specific file or data I can debug to help make things clear so we can find the bottom of it, please, let me know.

KoolReport commented on Aug 4, 2022

Yes, I understand. The dev.team was able to replicate the issue from your information. They confirmed the issue was fixed.

GHSix commented on Aug 4, 2022

Oh I see. Thank you.

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
suggestion

Dashboard