Skip to content

Commit

Permalink
Merge pull request #157 from eugenem/development
Browse files Browse the repository at this point in the history
select column fixes and improvements
  • Loading branch information
sleeping-owl committed Jun 28, 2015
2 parents e75406e + 7d05a5d commit 54d91a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
25 changes: 21 additions & 4 deletions src/SleepingOwl/Admin/ColumnFilters/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Select extends BaseColumnFilter
protected $display = 'title';
protected $options = [];
protected $placeholder;
protected $filter_field = '';

/**
* Initialize column filter
Expand All @@ -23,6 +24,15 @@ public function initialize()
AssetManager::addScript('admin::default/js/columnfilters/select.js');
}

public function filter_field( $field = null )
{
if(is_null($field))
return $this->filter_field;

$this->filter_field = $field;
return $this;
}

public function model($model = null)
{
if (is_null($model))
Expand Down Expand Up @@ -90,11 +100,18 @@ public function getParams()
];
}

public function apply($repository, $column, $query, $search, $fullSearch, $operator = 'like')
public function apply($repository, $column, $query, $search, $fullSearch, $operator = '=')
{
if (empty($search)) return;
#if (empty($search)) return;
if ($search === '') return;

if ($operator == 'like')
if($this->filter_field())
{
$query->where($this->filter_field(), '=', $search);
return;
}

if ($operator == 'like')
{
$search = '%' . $search . '%';
}
Expand All @@ -115,4 +132,4 @@ public function apply($repository, $column, $query, $search, $fullSearch, $opera
}
}

}
}
6 changes: 3 additions & 3 deletions src/views/default/columnfilter/select.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<select class="form-control column-filter" data-type="select">
<option value="">- {{ $placeholder }} -</option>
@foreach ($options as $option)
<option value="{{ $option }}">{{ $option }}</option>
@foreach ($options as $key => $option)
<option value="{{ $key }}">{{ $option }}</option>
@endforeach
</select>
</select>

0 comments on commit 54d91a5

Please sign in to comment.