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 - 8 comments

GHSix commented on Aug 2

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 7 days ago

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 7 days ago

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 6 days ago

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 6 days ago

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

KoolReport commented 6 days ago

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 6 days ago

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 5 days ago

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

GHSix commented 5 days ago

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