Hello Team,
I have been stuck for a couple of days trying to use Select2, Multiselect, BSelect, Etc with the default of ALL the data in the column.
Normally when I use select option I do a WHERE LIKE :selection in my SQL so I can have % as default and it will select everything by default unless I select something specific in the drop down.
I have seen examples with WHERE IN :selection but I need to still have the default be ALL
Below is examples of my Report and it seems everything I try fails either on report open for selecting all or when I try and select multiple options after the report shows all
event_list produces the list of options in the select dropdown and event_name is what I insert in MySQL query for results after the event is selected in the drop down. If the user does not select anything all data is shown.
SigEventReport.php SigEventReport.view.php
Again I have no problem with Select Option but when I try to implement any Select2 or other multiselect I can not get it to work as select all by default or select multiple options manually.
As always if you can help me with this I will gladly give a Tip!!! Here is examples of the last way I have tried to do it.
SigEventReport.view.php
   /**
     * @return array[]
     */
    protected function defaultParamValues(): array
    {
        return array(
            "dateRange",
            "user_name"=>"%",
            "event_name"=>array(),
            //"multiSelect"=>$allMultiSelectData,
        );
    }
    /**
     * @return string[]
     */
    protected function bindParamsToInputs(): array
    {
        return array(
            "dateRange"=>"dateRange",
            "user_name",
            "event_name"=>"event_name",
            "loadData",
        );
    }
    $sql_event_list = "
                    SELECT
                    a.activity_type_field AS event
                    FROM activities a
                    -- WHERE a.activity_type_field is not null
                    GROUP BY a.activity_type_field
    ";
    //event list for sig event report
    $this->src('lp3')->query($sql_event_list)
    ->pipe($this->dataStore("event_list"));
    $sql_sig_event_data = "
                        SELECT
                        a.activity_date AS Date,
                        u.user_name AS Emp,
                        a.activity_type_field AS Event,
                        a.activity_log Description 
                        FROM activities a
                        LEFT JOIN users u ON u.user_id = a.activity_user_id
                        WHERE activity_date > :start
                        AND activity_date < :end
                        AND u.user_name LIKE :emp
                        
                        // ****************************************************************
                        // Normally I have AND a.activity_type LIKE :event
                        // I need this to show all events by default unless I am choosing one or more events
                        AND a.activity_type_field IN :event
                        AND a.activity_status != 12
    ";
    // pipe table data to sig event report UI
    $this->src('lp3')->query($sql_sig_event_data)
        ->params(array(
            ":start" => $this->params["dateRange"][0],
            ":end" => $this->params["dateRange"][1],
            ":emp" => $this->params["user_name"],
            ":event" => $this->params["event_name"],
    ))
    ->pipe($this->dataStore("sig_event_report"));
//*****************************************************************
sigEventReport.php
    <?php
        // Select::create(array(
        // "name"=>"event_name",
        // //"placeholder"=>"Event Name",
        // "multiple"=>true,
        // "dataStore"=>$this->dataStore("event_list"),
        // "defaultOption"=>array("All"=>"%"),
        // "dataBind"=>array(
        //     "text"=>"event",
        //     "value"=>"event",
        // ),
        // "attributes"=>array(
        //     "class"=>"form-control",
        //     "style"=>"margin-top:10px;width: 300px;padding: 0;font-size: 1em;"
        // )
        // ));
    
        Select2::create(array(
        "name"=>"event_name",
        //"placeholder"=>"Event Name",
        "multiple"=>true,
        "dataStore"=>$this->dataStore("event_list"),
        "defaultOption"=>array("All"=>"%"),
        "dataBind"=>array(
            "text"=>"event",
            "value"=>"event",
        ),
        "attributes"=>array(
            "class"=>"form-control",
            "style"=>"margin-top:10px;width: 300px;padding: 0;font-size: 1em;"
        )
        ));
    
        // MultiSelect::create(array(
        // "name"=>"event_name",
        // //"placeholder"=>"Event Name",
        // "multiple"=>true,
        // "dataStore"=>$this->dataStore("event_list"),
        // //"defaultOption"=>array("All"=>"%"),
        // "dataBind"=>array(
        //     "text"=>"event",
        //     "value"=>"event",
        // ),
        // "attributes"=>array(
        //     "class"=>"form-control",
        //     "style"=>"margin-top:10px;width: 300px;padding: 0;font-size: 1em;"
        // )
        // ));
        
        
        // BSelect::create(array(
        //     "name"=>"event_name",
        //     "multiple"=>true,
        //     "dataStore"=>$this->dataStore("event_list"),
        //     //"defaultOption"=>array("All"=>"%"),
        //     "dataBind"=>array(
        //         "text"=>"event",
        //         "value"=>"event",
        //     ),
        //     'options' => array(
        //         'numberDisplayed' => 5,
        //         'includeSelectAllOption' => true,
        //         'includeResetOption' => true,
        //     ),
        //     "attributes"=>array(
        //         "class"=>"form-control",
        //         "style"=>"margin-top:10px;width: 300px;padding: 0;font-size: 1em;"
        //     )
        // ));








