Skip to content

Commit

Permalink
support multi column search (individual search)
Browse files Browse the repository at this point in the history
  • Loading branch information
hermawanramadhan committed Mar 30, 2021
1 parent 2924d15 commit 1632ef3
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/DataTableQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,43 @@ private function queryFilterSearch($builder)
{
$doQuerying = FALSE;

$columns = $this->getColumns();

//individual column search (multi column search)
foreach (DataTable::request('columns') as $index => $dtColumn)
{

if($dtColumn['search']['value'] != '')
{

if($this->returnAsObject)
{
if($dtColumn['name'])
$column = trim($dtColumn['name']);
elseif(in_array($dtColumn['data'], $columns))
$column = array_search($dtColumn['data'], $columns);

else
$column = $dtColumn['data'];
}
else
{
$keyColumns = array_keys($columns);
$column = $keyColumns[$index];
}



$builder->like(trim($column), $dtColumn['search']['value']);
$doQuerying = TRUE;
}
}

//global search
$dtSearch = DataTable::request('search');
$searchValue = $dtSearch['value'];

if($searchValue)
if($searchValue != '')
{

if($this->searchableColumns !== NULL)
Expand All @@ -277,7 +310,6 @@ private function queryFilterSearch($builder)
}
else
{
$columns = $this->getColumns();

if($this->returnAsObject)
{
Expand Down

0 comments on commit 1632ef3

Please sign in to comment.