KoolReport's Forum

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

How to create clickable link to another report with parameters #556

Open KoolReport opened this topic on on Dec 11, 2018 - 5 comments

KoolReport commented on Dec 11, 2018

(A nice question from our user)

Hi,

the koolreport looks very cool :-) thanks but I have one question because I am not sure can i do the following or not - For example, if i have a report

! date ! sales !

Is it possible to make the values in sales column clickable and open a new report with a different query by clicking on it - for example the list of orders on this date etc. So it must be a totally different query that should get the parameters depends on the clicked value

I've found Drilldown package but it looks like (based on examples) it uses the same query.... sorry I did not do a deep investigation because I just try to choose the optimal framework for me but this option is very important for my case.

KoolReport commented on Dec 11, 2018

It is totally possible and actually quite simple with formatValue property of Table:

Table::create(array(
    ...
    "columns"=>array(
        "date",
        "sale"=>array(
            "formatValue"=>function($value,$row){
                return "<a href='sale_detail.php?date=".$row['date']."'>$value</a>";
            }
        )
    )
));

And then in the sale_detail.php, you can initiate new report called SaleDetail received "date" as parameters and return list of sales on that date.

//sale_detail.php
$report = new SaleDetail(array(
    "date"=>$_GET["date"]
));
$report->run()->render();

In the SaleDetail, you can get the parameter date through $this->params["date"] for your another query to get list of all sale on that day.

Hope that helps.

Andrew Borell commented on Dec 12, 2018

This is a great example of something I meant to include in a reply to someone else who was asking on a similar topic. Thanks for posting this!

Eugene commented on Jan 31, 2019

Hi, I follow this recipe for my column 'cost' with 'id' as the parameter and everything is nice - links work as I need

but if I use grouping for this column to get the sum in the footer - the total sum amount becomes the link also, but it is not what I need and also it can not work because this total raw doesn't have id.

KoolReport commented on Feb 1, 2019

Hi Eugene,

Your raised issue is very interesting, here is the solution:

            "formatValue"=>function($value,$row){
                if($row)
                {
                    return "<a href='sale_detail.php?date=".$row['date']."'>$value</a>";
                }
                return $value;
            }

Basically, in the footer format, $row will not be available, so we just return the value or format it in the way we want without link. We only return the link in case there is $row as we know it is the row in table.

I really love your question, Eugene. There are a lot of features/ways that we could not able to write all in the documentation ( although we are trying). And from the questions of forums, we are able to give solutions and forum could be a knowledge base for problem and solution.

Eugene commented on Feb 1, 2019

Thank you :-) I like to use koolreport it is really easy to use even with minimal knowledge of PHP and JS but the devil is always in the details :-), so this forum is very helpful Thanks for your support...

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
wiki

None