title: Codeigniter and Datatable Search Filter Column problem
body: <p>Hello i have a little problem,
  i followed <a href="https://www.webslesson.info/2016/12/datatables-server-side-processing-in-%20%20codeigniter-using-ajax.html" rel="nofollow noreferrer">a tutorial</a> to make a datatable with codeigniter and next i tried to implement a search Column with <a href="https://www.webslesson.info/2017/07/datatables-individual-column-searching-%20%20using-php-ajax-jquery.html" rel="nofollow noreferrer">this tutorial</a>.</p>
  
  <p>My view:</p>
  
  <pre><code>&lt;div id="page-wrapper"&gt;
      &lt;div class="card"&gt;
          &lt;div class="card-header corsi"&gt;
              &lt;h3 class="page-header"&gt;&lt;i class="fas fa-graduation-cap"&gt;&lt;/i&gt; &lt;?=$title?&gt;&lt;/h3&gt;
          &lt;/div&gt;
          &lt;div class="card-body"&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-xl-12"&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-lg-12"&gt; 
                      &lt;table class="table table-striped table-bordered table-hover" id="scadenze_data" style="width:100%"&gt;
                          &lt;thead&gt;  
                              &lt;tr&gt;  
                                  &lt;th width="7%"&gt;Cod. Corso&lt;/th&gt;
                                  &lt;th width="9%"&gt;Nome&lt;/th&gt;  
                                  &lt;th width="10%"&gt;Cognome&lt;/th&gt;
                                  &lt;th width="7%"&gt;Codice Fiscale&lt;/th&gt;
                                  &lt;th width="7%"&gt;Azienda&lt;/th&gt;
                                  &lt;th width="1%"&gt;Edizione&lt;/th&gt;
                                  &lt;th width="1%"&gt;
                                      &lt;select name="profilo" id="profilo" class="form-control"&gt;
                                          &lt;option value=""&gt;Profilo Search&lt;/option&gt;
                                          &lt;?php 
                                              foreach($profili as $prof) {
                                                  echo '&lt;option value="'.$prof-&gt;CODICE.'"&gt;'.$prof-&gt;CODICE.'&lt;/option&gt;';
                                              }
                                          ?&gt;
                                      &lt;/select&gt;                      
                                  &lt;/th&gt;
                                  &lt;th width="9%"&gt;Periodo dal&lt;/th&gt;
                                  &lt;th width="9%"&gt;Periodo al&lt;/th&gt;  
                                  &lt;th width="9%"&gt;N. Attestato&lt;/th&gt; 
                                  &lt;th width="9%"&gt;Data attestato&lt;/th&gt; 
                                  &lt;th width="9%"&gt;Scadenza&lt;/th&gt;
                                  &lt;th width="9%"&gt;Attestati&lt;/th&gt;  
                              &lt;/tr&gt;  
                          &lt;/thead&gt;
                      &lt;/table&gt;  
                  &lt;/div&gt;  
              &lt;/div&gt; 
          &lt;/div&gt;
          &lt;div class="card-footer"&gt;
              &lt;div class="container-fluid"&gt;
                  &lt;div class="row"&gt;
                      &lt;div class="col-md-6"&gt;
                          &lt;input class="btn btn-secondary" src="" value="&lt;- Torna indietro"&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;  
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;              
  &lt;/div&gt;
  &lt;script type="text/javascript" language="javascript" &gt; 
      $(document).ready(function(){  
          load_data();
  
          function load_data(is_profilo) {
              var dataTable = $('#scadenze_data').DataTable({ 
                  "searchable": true,
                  "Paginate": true, 
                  "processing":true,  
                  "serverSide":true,  
                  "order":[],  
                  "ajax":{  
                      url:"&lt;?php echo base_url().'corsi/fetch_scadenze'; ?&gt;",  
                      type:"POST",
                      data:{is_profilo:is_profilo}
                  },  
                  "columnDefs":[  
                      {  
                          "targets":[12],  
                          "orderable":false,  
                      },
                      {  
                          "targets":[6],  
                          "orderable":false,  
                      },
                  ],
                  "deferRender": true,
                  "lengthMenu":[[10,25,50,100,-1],[10,25,50,100,"All"]],
                  "pageLength":10,
                  "pagingType": "full_numbers",
              }); 
          }
  
          $(document).on('change', '#profilo', function(){
              var profilo = $(this).val();
              $('#scadenze_data').DataTable().destroy();
              if(profilo != '') {
                  load_data(profilo);
              } else {
                  load_data();
              }
          });
      }); 
  &lt;/script&gt; 
  </code></pre>
  
  <p>My controller:</p>
  
  <pre><code>function fetch_scadenze(){ 
      $this-&gt;load-&gt;helper('form');
      $this-&gt;load-&gt;model("scadenze_model");
      $fetch_data = $this-&gt;scadenze_model-&gt;make_datatables();  
      $data = array();  
      foreach($fetch_data as $row) {  
          $dal = date("d/m/Y", strtotime($row-&gt;PERIODO_DAL));
          $al = date("d/m/Y", strtotime($row-&gt;PERIODO_AL));
          $att = date("d/m/Y", strtotime($row-&gt;DATA_ATTESTATO));
          $scadenza = date("d/m/Y", strtotime($row-&gt;DATA_SCADENZA));
          $sub_array = array(); 
          $sub_array[] = $row-&gt;CORSOCODICE;
          $sub_array[] = $row-&gt;NOME;  
          $sub_array[] = $row-&gt;COGNOME;
          $sub_array[] = $row-&gt;CF;
          $sub_array[] = $row-&gt;DENOMIN_RAG_SOC;
          $sub_array[] = $row-&gt;EDIZIONE;
          $sub_array[] = $row-&gt;CODICE;
          $sub_array[] = $dal;
          $sub_array[] = $al;
          $sub_array[] = $row-&gt;N_ATTESTATO_PROGRESSIVO;
          $sub_array[] = $att;
          $sub_array[] = $scadenza;
          $sub_array[] = "&lt;div class='btn-group' role='group' aria-label='Button group with nested dropdown'&gt;...&lt;/div&gt;";  
          $data[] = $sub_array;  
      }  
      $output = array(  
          "draw" =&gt; intval($_POST["draw"]),  
          "recordsTotal" =&gt; $this-&gt;scadenze_model-&gt;get_all_data(),  
          "recordsFiltered" =&gt; $this-&gt;scadenze_model-&gt;get_filtered_data(), 
          "data" =&gt; $data
      );
      echo json_encode($output);
  }
  </code></pre>
  
  <p>And my Modal:</p>
  
  <pre><code>if (!defined('BASEPATH')) {exit('No direct script access allowed');}
  
  class Scadenze_model extends CI_Model  
  {  
      var $table = "corso co";  
      var $select_column = array("cu._ID","ut.NOME","ut.COGNOME","ut.CF","az.DENOMIN_RAG_SOC","co.EDIZIONE","pr.CODICE","co.CORSOCODICE","co.PERIODO_DAL","co.PERIODO_AL","cu.N_ATTESTATO_PROGRESSIVO","co.DATA_ATTESTATO","co.DATA_SCADENZA","cu.FILE");
      var $order_column = array("co.CORSOCODICE","ut.NOME","ut.COGNOME","ut.CF","az.DENOMIN_RAG_SOC","co.EDIZIONE","pr.CODICE","co.PERIODO_DAL","co.PERIODO_AL","cu.N_ATTESTATO_PROGRESSIVO","co.DATA_ATTESTATO","co.DATA_SCADENZA", null);
  
      function make_query()  
      {  
          $this-&gt;db-&gt;select($this-&gt;select_column);  
          $this-&gt;db
              -&gt;from($this-&gt;table)
              -&gt;join("corsi_utenti cu", "co._ID = cu.ID_CORSO", "left")
              -&gt;join("azienda az", "cu.ID_AZIENDA = az._ID", "left")
              -&gt;join("utente ut", "cu.ID_UTENTE = ut._ID", "left")
              -&gt;join("profilo pr", "co.ID_PROFILO = pr._ID", "left");
  
          if(isset($_POST["is_profilo"])) 
          {
              //echo "&lt;script type='text/javascript'&gt;console.log('prova');&lt;/script&gt;";
              $this-&gt;db-&gt;or_like("pr.CODICE", $_POST["is_profilo"]);
              //$this-&gt;db-&gt;or_like("pr.CODICE", $_POST["is_profilo"]["value"]);
              //$query .= "product.category = '".$_POST["is_category"]."' AND ";
          }
          if(isset($_POST["search"]["value"]))  
          {   //echo "&lt;script&gt;alert('There are no fields to generate a report');&lt;/script&gt;";
              $this-&gt;db-&gt;like("co.CORSOCODICE", $_POST["search"]["value"]);
              $this-&gt;db-&gt;or_like("ut.NOME", $_POST["search"]["value"]);
              $this-&gt;db-&gt;or_like("ut.COGNOME", $_POST["search"]["value"]);
              $this-&gt;db-&gt;or_like("ut.CF", $_POST["search"]["value"]);
              $this-&gt;db-&gt;or_like("az.DENOMIN_RAG_SOC", $_POST["search"]["value"]);
              $this-&gt;db-&gt;or_like("co.EDIZIONE", $_POST["search"]["value"]);
              $this-&gt;db-&gt;or_like("pr.CODICE", $_POST["search"]["value"]);
              $this-&gt;db-&gt;or_like("co.PERIODO_DAL", $_POST["search"]["value"]);
              $this-&gt;db-&gt;or_like("co.PERIODO_AL", $_POST["search"]["value"]);
              $this-&gt;db-&gt;or_like("cu.N_ATTESTATO_PROGRESSIVO", $_POST["search"]["value"]);
              $this-&gt;db-&gt;or_like("co.DATA_ATTESTATO", $_POST["search"]["value"]);
              $this-&gt;db-&gt;or_like("co.DATA_SCADENZA", $_POST["search"]["value"]);
          } 
          if(isset($_POST["order"]))  
          {  
              $this-&gt;db-&gt;order_by($this-&gt;order_column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);  
          } else {  
              $this-&gt;db-&gt;order_by('co.DATA_ATTESTATO', 'DESC');
          }  
      }  
      function make_datatables()
      {
          $this-&gt;make_query();
  
          // $this-&gt;db-&gt;limit(10,1);
          if($_POST['length'] != -1)  
          {  
              $this-&gt;db-&gt;limit($_POST['length'], $_POST['start']);  
          }
          $query = $this-&gt;db-&gt;get();  
          return $query-&gt;result();  
      }  
      function get_filtered_data(){  
          $this-&gt;make_query();  
          $query = $this-&gt;db-&gt;get();  
          return $query-&gt;num_rows();  
      }       
      function get_all_data()  
      {  
          $this-&gt;db-&gt;select("*");  
          $this-&gt;db-&gt;from($this-&gt;table);  
          return $this-&gt;db-&gt;count_all_results();  
      }
  
  
      function insert_log($activity, $module){
          $id = $this-&gt;session-&gt;userdata('user_id');
  
          $data = array(
              'fk_user_id' =&gt; $id,
              'activity'   =&gt; $activity,
              'module'     =&gt; $module,
              'created_at' =&gt; date('Y\-m\-d\ H:i:s A')
          );
          $this-&gt;db-&gt;insert('activity_log', $data);
      }
  
      //FACCIO UPDATE DELLA TABELLA corsi_utenti in FILE        
      function set_url_attestato($id, $file){
          $this-&gt;db-&gt;set('FILE', $file);
          $this-&gt;db-&gt;where('_ID', $id);
          $this-&gt;db-&gt;update('corsi_utenti');        
      }
  }
  </code></pre>
  
  <p>My datatable refreshes but doesn't work when i select the dropdown to choose the "profilo".</p>
  
  <p>Thx.</p>