Example 07:

This example show you how to:

  • Load the plugin
  • Add a Button that show you the selected rows
  • Select rows by default when page load

HTML :
<select id="country_id" class="mSelect" multiple="multiple"></select>
JS :
$(function () {
    $('#country_id').mSelect({
        url: 'ajax/example4.php',
        selectedIds: ["3","4","14","231","109"], // the ids to select by default
        btnSelected:{
            enable: true
        }
    });
});
PHP :
<?php 
    //........
    // get the selected rows ids
    $selectedIds = isset($_GET['ids']) && !empty($_GET['ids']) ? $_GET['ids'] : []; 
    $whereResult = !empty($selectedIds) ? "id IN($selectedIds)" : null;
    
    echo json_encode(
       Datatables::complex($_GET, $sql_details, $table, $primaryKey, $columns, $whereResult, $whereAll = null)
    );
?>