0

Select DropDown ImageEpisode 2 I’ve update the DataTables php code to search and collect the data that is add or reduce the json data that is used by yadcf. How do I prevent yadcf on updating that column list of options values if a value is already selected to the filter? When I reselect the filter all of the previous options are removed, which I don’t want if someone selects the wrong option. I would have use the below if to prevent that select to update. Also, the reset button is not an option I want to use.

if ( strindex[w] === 3 && GBselBoxphp3 === '' ) {
    var selectoptdata = data.yadcf_data_3;
    select.empty().append('<option value=""/>');

    $.each(selectoptdata, function (i, j) {
        select.append( '<option value="'+j+'">'+j+'</option>' )
    }); 
}   

Episode 1 The solution that you had obtained from Allan Jardine to populate column dropdown had cleared one more hurdle so I can implement server-side processing to my DataTables, but adding the changes mentioned below to ssp.class.php has impaired cumulative filtering. Cumulative filtering a very useful feature when narrowing down a selected record. Any idea how this could be corrected?

stackoverflow.com/questions/41507443/yadcf-datatables-server-side-populate-select-with-php

$data=SSP::simple( $_POST, $sql_details, $table, $primaryKey, $columns);

$db = SSP::sql_connect( $sql_details );
$stmt3 = $db->prepare( 'SELECT DISTINCT(value) FROM table' );
$stmt3->execute();
$data['yadcf_data_3'] = $stmt3->fetchAll(PDO::FETCH_COLUMN, 0);

$stmt5 = $db->prepare( 'SELECT DISTINCT(value2) FROM table' );
$stmt5->execute();
$data['yadcf_data_5'] = $stmt5->fetchAll(PDO::FETCH_COLUMN, 0);

$stmt6 = $db->prepare( 'SELECT DISTINCT(value3) FROM table' );
$stmt6->execute();
$data['yadcf_data_6'] = $stmt6->fetchAll(PDO::FETCH_COLUMN, 0);


echo json_encode($data);

This is what I have done to the php code to column 3. This also take in the value entered into the search box from Datatables.

if( !empty($requestData['columns'][3]['search']['value']) ){ 
        $strselBoxphp3 = $requestData['columns'][3]['search']['value']; 
    } else {
        $strselBoxphp3 = ""; 
    }       

    //Column 3 DropDown Data
    $db=SSP::sql_connect( $sql_details );
        if( !empty($strsrchBoxvaluephp) ) {
            $sql  = ' SELECT DISTINCT SVD_Description FROM SVD_Equipment WHERE'; 
            $sql .= ' (SVDid LIKE "%'.$strsrchBoxvaluephp.'%"'; 
            $sql .= ' OR Audit LIKE "%'.$strsrchBoxvaluephp.'%"';
            $sql .= ' OR SVD_Description  LIKE "%'.$strsrchBoxvaluephp.'%"';
            $sql .= ' OR Manufacture LIKE "%'.$strsrchBoxvaluephp.'%"';
            $sql .= ' OR Model LIKE "%'.$strsrchBoxvaluephp.'%"';
            $sql .= ' OR VIN LIKE "%'.$strsrchBoxvaluephp.'%"';
            $sql .= ' OR State LIKE "%'.$strsrchBoxvaluephp.'%"'; 
            $sql .= ' OR License_Plate_Number LIKE "%'.$strsrchBoxvaluephp.'%"'; 
            $sql .= ' OR License_Plate_Expiration_Date LIKE "%'.$strsrchBoxvaluephp.'%"';
            $sql .= ' OR Last_Inspection_Date LIKE "%'.$strsrchBoxvaluephp.'%"';
            $sql .= ' OR Primary_Tech LIKE "%'.$strsrchBoxvaluephp.'%"'; 
            $sql .= ' OR Manager LIKE "%'.$strsrchBoxvaluephp.'%")';
        } else {
            $sql = 'SELECT DISTINCT SVD_Description FROM SVD_Equipment WHERE SVD_Description != ""';
        }                       

        if( !empty($strselBoxphp2) ) { 
            $sql .= ' AND Audit = "'.$strselBoxphp2.'"';
        }
        if( !empty($strselBoxphp4) ) { 
            $sql .= ' AND Manufacture = "'.$strselBoxphp4.'"';
        }       
        if( !empty($strselBoxphp5) ) { 
            $sql .= ' AND Model = "'.$strselBoxphp5.'"';
        }       
        if( !empty($strselBoxphp11) ) { 
            $sql .= ' AND Primary_Tech = "'.$strselBoxphp11.'"';
        }   
        if( !empty($strselBoxphp12) ) { 
            $sql .= ' AND Manager = "'.$strselBoxphp12.'"';
        }   

        $sql .= ' ORDER BY SVD_Description;';
    $stmt3 = $db->prepare($sql);
    $stmt3->execute();
    $data['yadcf_data_3'] = $stmt3->fetchAll(PDO::FETCH_COLUMN, 0);
Pappas
  • 27
  • 4
  • you should query those rows that the current selected values are present inside them (ni the relevant columns) , you can do some "post processing (that data that got back from sql) in php code" – Daniel Feb 09 '18 at 20:33
  • 1
    I was able to correct my issue by improving the logic when building the sql string. The above has been edited that resolved my issue. Why I added the " else $strselBoxphp3 = ""; " to the "if !empty($requestData)" columns when I select an empty option in the dropdown it would rebuild the options list. – Pappas Feb 19 '18 at 04:12

0 Answers0