Mysql
 sql >> Base de données >  >> RDS >> Mysql

Datatables rejoignant les tables de recherche et de commande bloquées avec codeigniter

en fonction de vos modèles, vous pouvez le modifier comme ci-dessous

private function _get_datatables_query($term=''){ //term is value of $_REQUEST['search']['value']
    $column = array('k.id_kota','k.nm_kota', 'p.nm_propinsi');
    $this->db->select('k.id_kota, k.nm_kota, p.nm_propinsi');
    $this->db->from('kota as k');
    $this->db->join('propinsi as p', 'p.id_propinsi = k.id_propinsi','left');
    $this->db->like('k.id_kota', $term);
    $this->db->or_like('k.nm_kota', $term);
    $this->db->or_like('p.nm_propinsi', $term);
    if(isset($_REQUEST['order'])) // here order processing
    {
       $this->db->order_by($column[$_REQUEST['order']['0']['column']], $_REQUEST['order']['0']['dir']);
    } 
    else if(isset($this->order))
    {
       $order = $this->order;
       $this->db->order_by(key($order), $order[key($order)]);
    }
}

function get_datatables(){
  $term = $_REQUEST['search']['value'];   
  $this->_get_datatables_query($term);
  if($_REQUEST['length'] != -1)
  $this->db->limit($_REQUEST['length'], $_REQUEST['start']);
  $query = $this->db->get();
  return $query->result(); 
}

function count_filtered(){
  $term = $_REQUEST['search']['value']; 
  $this->_get_datatables_query($term);
  $query = $this->db->get();
  return $query->num_rows();  
}

public function count_all(){
  $this->db->from($this->table);
  return $this->db->count_all_results();  
}