KoolReport's Forum

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

Add a button to load other dash in Datatables #2449

Closed Mathieu Viennet opened this topic on on Nov 21, 2021 - 13 comments

Mathieu Viennet commented on Nov 21, 2021

Hi!

I'm using the Dashboard Framework. I basically want to do exactly as your Customers example (have a button that loads another Dashboard with the invoice details when clicked :

I'm using Datatables and would like to know if it's possible to create what i want with Datatables? The main purpose of Datatables is the table sorting, which i can't do with the default Koolreport table...

Thanks!

KoolReport commented on Nov 22, 2021

The Dashboard table ( in your screen shoot) can do sorting as well and it is even more efficient loading than datatables as it does not load all data while sorting.

View the example with sorting

Let us know if you need further assistance.

Mathieu Viennet commented on Nov 22, 2021

Thank you!

Questions :

1 - Can i make the whole column header clickable? Instead of having to click on that little tiny arrow?

2 - Can the behavior of the sort be to reset the other sorts? Let say, if i order by date, then i click order by revenu, it will reset the order by date sort? The issue here is that when i sort by date, if the user doesn't remove the sorting from the date column, he cannot sort by the other columns... The same thing happen in your example : if the date column is sorted, when you click on the "Status" column, nothing happens...

Thanks!

Mathieu Viennet commented on Nov 22, 2021

I followed the example, but when i click on the button to load the second dashboard, i get this error :

Message: Call to undefined method koolreport\dashboard\Response::nextHandler()
Line: 164
File: /home/xxxxxx/public_html/reports/koolreport/dashboard/pages/Main.php
KoolReport commented on Nov 22, 2021

This error normally appear when app could not find the dashboard, please check if you have registered the second dashboard to App.php inside "dashboads()" method

Mathieu Viennet commented on Nov 22, 2021

OK, so it seems i need to create a menu link in APP.php to the second dashboard for it to work...in protected function dashboards()

is there another way to make that dashboard "active" without creating a menu?

KoolReport commented on Nov 22, 2021

For your questions:

1 - Can i make the whole column header clickable? Instead of having to click on that little tiny arrow?

Answer: That's a great suggestion, I will forward your idea to dev.team. Personally I think it is more user-friendly to be so.

2 - Can the behavior of the sort be to reset the other sorts? Let say, if i order by date, then i click order by revenu, it will reset the order by date sort? The issue here is that when i sort by date, if the user doesn't remove the sorting from the date column, he cannot sort by the other columns... The same thing happen in your example : if the date column is sorted, when you click on the "Status" column, nothing happens...

Answer: Actually, when you have both columns sorted then both columns will go to SQL Order By. As you know the order of columns in "order by" is important, it determine which columns will be sorted first before other can be sorted. So in this case, the date column will be sorted first. And only if there is two rows with same date, then the status will have chance to be sorted. That's why you see this effect like nothing happens when you sort the status column after sorting date.

3 - dashboard "active" without creating a menu?

Answer: You simply adding "->hidden(true)" then it will be out of menu.

Mathieu Viennet commented on Nov 22, 2021

Thank you very much for your nice answer :)

Another question i have while working with 2 dashboards :

In the first report, i have a daterangepicker. How can i pass its current value as a parameter to the second report ?

See below "date_start"

 Button::create("viewDetails")
                ->type("warning")
                ->textAlign("right")
                ->text("View Details")
                ->onClick(function($value, $row){
                    return Client::dashboard("SalesByRepCustomerDetail")->load([
                        "customer_name"=>$row["customer_name"],
                        "date_start"=>$start
                        
                    ]);
KoolReport commented on Nov 22, 2021

Could you please give me some screenshoot of two dashboard so I can understand your business logic. May be you can explain abit about what you trying to do.

Mathieu Viennet commented on Nov 22, 2021

Hi, I created a quick video for you, hope this is clear! :

removed link

KoolReport commented on Nov 22, 2021

Hi Mathieu,

Awesome explanation from you.

Here is what you can do:

 Button::create("viewDetails")
                ->type("warning")
                ->textAlign("right")
                ->text("View Details")
                ->onClick(function($value, $row){
                    return Client::dashboard("SalesByRepCustomerDetail")->load([
                        "customer_name"=>$row["customer_name"],
                        "date_start"=>$this->widget()->sibling("yourDateRangePickerName")->value()[0]
                        
                    ]);

Basically, you can access the Table object from the Button field with $this->widget(), and from the table you can access the the DateRangePicker by ->sibling() method. The value returned by DateRangePicker is an array of start date and end date so to access the start date you do:

$this->widget()->sibling("yourDateRangePickerName")->value()[0]

Let me know if it works.

Mathieu Viennet commented on Nov 22, 2021

T.h.a.n.k. y.o.u. !

Works as expected :)

Mathieu Viennet commented on Nov 22, 2021

KoolReport commented on Nov 22, 2021

Awesome :)

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

Dashboard