KoolReport's Forum

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

Dashboard Two selectlists - parent and child #3360

Open Marloes opened this topic on 5 days ago - 1 comments

Marloes commented 5 days ago

Hi,

Is there a possibilty in de Dashboard to have 2 selectlists which are cascading? Just like: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_cascading_dropdown

So you have a parent seleclists which reloads the dataset of it's child seleclist.

With kind regards, Marloes

Sebastian Morales commented 4 days ago

I think it's possible. You need to catch the parent select's change and update the child select accordingly like this:

class MyBoard extends \koolreport\dashboard\Dashboard
{
    protected function widgets()
    {       

        return [
            ...
            Row::create([
                [
                    Html::label("Parent")->style("font-weight:bold"),
                    BSelectParent::create(),
                ],
                [
                    Html::label("Child")->style("font-weight:bold"),
                    BSelectChild::create(),
                ],
    }
}


class BSelectParent extends \koolreport\dashboard\inputs\BSelect
{
    ...

    protected function actionChange($request, $response)
    {
        $this->sibling("BSelectChild")->update(); // update the child select
    }
}


class BSelectChild extends \koolreport\dashboard\inputs\BSelect
{

    protected function onInit()
    {        
        $parent = $this->sibling('BSelectParent')->value() ?? null; // scalar or array value depending on whether BSelectParent is single or multipel select
        $selectData = ...;
        
        $this
            ->props([
                "dataSource" => $selectData,
                "dataBind"=>[
                    "value" => ...,
                    "text" => ...,
                ],
            ]); 
    }
} 

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