KoolReport's Forum

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

Why does not it work #2212

Closed Eugene opened this topic on on Jul 19, 2021 - 4 comments

Eugene commented on Jul 19, 2021

Hi, wish to add some logic to the grouping rules but I think i did something wrong

"grouping" => function () {
                return array(
                    "category" => array(
                    "top" => "<td colspan=\"3\" <td class='top_group'><b>{category} </b></td>"
                ));
            },

it does not work ((

but the following works fine

"grouping" => array(
                    "category" => array(
                    "top" => "<td colspan=\"3\" <td class='top_group'><b>{category} </b></td>",
                ),
),
KoolReport commented on Jul 19, 2021

Hi, the "grouping" receives array and does not receive function, that's why it does not work. Here is an work around if using function is necessary for you:

"grouping"=>(function(){
    return array(
        "category" => array(
        "top" => "<td colspan=\"3\" <td class='top_group'><b>{category} </b></td>"
    ));
})(),

Hope that helps

Eugene commented on Jul 19, 2021

Yes. It works. Thanks.

I know it is not the PHP classes but could you explain why does it work? ))))

KoolReport commented on Jul 19, 2021

It is short hand of defining anonymous function and immediately execute it, normally we do:

$myfunc = function(){
    //Do something
};
$myfunc(); // Execute it

Now we combine and make it shorter.

(function(){
    //Do something
})();
Eugene commented on Jul 19, 2021

Thanks a lot )))

It looks like in JS but I did not know it is possible in php

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