KoolReport's Forum

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

How to set default checked value of CheckBoxList ? #1349

Open TommyLo opened this topic on on Mar 17, 2020 - 1 comments

TommyLo commented on Mar 17, 2020

I am using Koolreport alongside with Laravel Framework. I wonder how to we set checked value of options on CheckBoxList, so by default when i go to that page, automatically the checkbox is checked ? My point of using CheckBoxList is for filtering purpose. I tried to use JQuery to set each of the CheckBoxList to checked, actually it works but got a problem. My report is being loaded from JS when the condition of CheckBox is not checked. Then I need to auto reload it one more time which is not efficient and very bad. From what i saw from koolreport docs, this feature is not state.

Christoph Paschen commented on Dec 31, 2022

Hi! I had the same issue in my project and here is the solution: Just a simple checkboxlist-object:

class SimpleCheckboxList extends CheckBoxList
{
    protected function dataSource()
    {
        return [
            [
                "id" => '1st',
                "name" => "first option",
            ],
            [
                "id" => '2nd',
                "name" => "second option",
            ],
            [
                "id" => '3rd',
                "name" => "third option",
            ],
        ];
    }

    protected function fields()
    {
        return [
            ID::create("id"),
            Text::create("name"),
        ];
    }
}

And now select the second option as default

SimpleCheckboxList::create()->defaultValue(array("2nd")),

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

Inputs