IgnitedDatatables / Ignited-Datatables

Ignited Datatables is a wrapper class/library based on the native Datatables server-side implementation by Allan Jardine found at http://datatables.net/examples/data_sources/server_side.html for CodeIgniter
285 stars 335 forks source link

Smart Search #139

Open Nounours13 opened 5 years ago

Nounours13 commented 5 years ago

Hi, I've a projet where i must use smart search on datatable (many word on many column). If anybody have the same problem, i've change the code to this (line 327)

  if($sSearch != '')
    {

      $sSearch_explode = explode(" ",$sSearch);
      foreach ($sSearch_explode as $sSearch)
        {
          $sWhere .= '(';
          for($i = 0; $i < count($mColArray); $i++)
          {
            if ($mColArray[$i]['searchable'] == 'true' && !array_key_exists($mColArray[$i]['data'], $this->add_columns))
              {
                if($this->check_cType())
                  {
                    $sWhere .= $this->select[$mColArray[$i]['data']] . " LIKE '%" . $sSearch . "%' OR ";
                  }               
                else
                  {
                    $sWhere .= $this->select[$this->columns[$i]] . " LIKE '%" . $sSearch . "%' OR ";
                  }

              }

          }
          $sWhere = substr_replace($sWhere, '', -3);
          $sWhere .= ') AND ';
        }

    }  

  $sWhere = substr_replace($sWhere, '', -4);
rorkyendo commented 4 years ago
private function get_filtering()
{
  $mColArray = $this->ci->input->post('columns');
  $sWhere = '';
  $search = $this->ci->input->post('search');
  $sSearch = $this->ci->db->escape_like_str(trim($search['value']));
  $columns = array_values(array_diff($this->columns, $this->unset_columns));
  if($sSearch != '')
    for($i = 0; $i < count($mColArray); $i++)
      if ($mColArray[$i]['searchable'] == 'true' && !array_key_exists($mColArray[$i]['data'], $this->add_columns))
      if (!empty($mColArray[$i]['data'])) {
        if($this->check_cType())
            $sWhere .= $mColArray[$i]['data'] . " LIKE '%" . $sSearch . "%' OR ";
        else
          $sWhere .= $this->select[$this->columns[$i]] . " LIKE '%" . $sSearch . "%' OR ";
        }
  $sWhere = substr_replace($sWhere, '', -3);
  if($sWhere != '')
    $this->ci->db->where('(' . $sWhere . ')');
  // TODO : sRangeSeparator
  foreach($this->filter as $val)
    $this->ci->db->where($val[0], $val[1], $val[2]);
}

i try to change like this, but you can't use order by on query. just use order on javascript of datatables it will ordering from server side too.

image