KoolReport's Forum

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

Initiallize a checkbox and trigger change in client side #902

Open iRiyada opened this topic on on Jun 2, 2019 - 5 comments

iRiyada commented on Jun 2, 2019

how to check a checkbox and trigger change on page load.

 <?php
CheckBoxList::create(array(
    "name"=>"having_task",
    "data"=>array(
        "Having Tasks"=>"yes",
        
    ),
    "clientEvents"=>array(
        "change"=> "function(params){
            var table = $('#example').DataTable();
              console.log('have_task');
        if(params.value[0]==='yes'){
                table.columns(5).search('yes').draw();
        }
        else
        $('#form1').submit();

    }"
),

));
?>

here, my check box is unchecked and works perfect when I check. But what I want is,

    1)to check this checkbox during page load itself.
   2)also to trigger change when checkbox is selected, 

this must be done on the client side.

iRiyada commented on Jun 2, 2019

By doing this I am able to display checked box. but the change event is not triggerred.

protected function defaultParamValues()
{
    
            return array(
     
        "having_task"=>["yes"],

        
  

    );

}
protected function bindParamsToInputs()
{
    return array(
      
        "having_task"
    );

    
}

KoolReport commented on Jun 2, 2019

Hi, I have not understood your requirement "to check this checkbox during page load itself", Could you please explain further?

iRiyada commented on Jun 3, 2019

I am using checkbox for data filtering in datagrid. If it is checked, rows are filtered. But I want it as filtered on page load itself. I have a change event for checkbox to filter the results on being checked, and it is working fine. Now I want this on page load itself. i.e. to trigger change event on page load by setting checkbox as checked while binding inputs.

At present, the checkbox is checked while the page is loaded. but change event is not triggerred. Hope that is clear now.

iRiyada commented on Jun 3, 2019

thank you, could solve it with this


  $('input[name="having_task[]"]:checked').length > 0   
                {
                    console.log("checking checked or not");
                    $("input[type=checkbox]").change();

                }
KoolReport commented on Jun 3, 2019

Great!

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
solved

None