Skip to content

Commit

Permalink
Fix table filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimonka2 committed Jul 23, 2020
1 parent 438a3a7 commit 0afe2a3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Form/Components/Table/ColumnsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function getVisibleColumnCount()
if($column->visible()) $count ++;
}
if($this->hasDetails()) $count ++;
if($this->hasSelect()) $count ++;
return $count;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Form/Components/Table/TableFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public function renderFilter($value)
return Flatform::render([
['div', 'class' => 'col-md-12', [$checkbox]]
]);
case 'text':
return Flatform::render([
['text', 'label' => $this->title, 'col' => 12, 'value' => $value, 'wire:model.debounce.500ms' => 'filtered.' . $this->name,]
]);
case 'select':
$list = $this->list;
if($list instanceof Closure) $list = $list(); // allow funciton as a list parameter
Expand Down
1 change: 1 addition & 0 deletions src/Livewire/TableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,5 +414,6 @@ public function __set($property, $value)
{
$this->WithPagination__set($property, $value);
$this->TableSearchQuery__set($property, $value);
// parent::__set($property, $value);
}
}
3 changes: 2 additions & 1 deletion src/Traits/TableSearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function initializeTableSearchQuery()
$this->updatesQueryString = array_merge([$this->searchQueryString => ['except' => '']], $this->updatesQueryString);
$this->updatesQueryString = array_merge([$this->filterQueryString => ['except' => []]], $this->updatesQueryString);
$this->search = request()->query($this->searchQueryString, $this->search);
$this->filter = request()->query($this->filterQueryString, $this->filtered);
$this->filtered = request()->query($this->filterQueryString, $this->filtered);
}

public function __get($property)
Expand All @@ -28,6 +28,7 @@ public function __get($property)

public function __set($property, $value)
{
// debug($property, $value);
if ($property == $this->searchQueryString) {
$this->search = $value;
} elseif($property == $this->filterQueryString) {
Expand Down
20 changes: 17 additions & 3 deletions views/livewire/table-filter.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
$checkbox,
]]
])
@break
@break
@case('select')
@php
$select = array_merge(
['select', 'label' => $title,
'selected' => $value,
'name' => $name,
'wire:model' => 'filtered.' . $name,
'col' => 12, 'list' => $filter->getList()
],
Expand All @@ -32,6 +33,19 @@
@endphp
@form([$select])
@break
@default
@break
@case('text')
@php
$_text = array_merge(
['text', 'label' => $title,
'value' => $value,
'name' => $name,
'wire:model.debounce.500ms' => 'filtered.' . $name,
'col' => 12,
],
$filter->getOptions([])
);
@endphp
@form([ $_text ])
@break
@endswitch

0 comments on commit 0afe2a3

Please sign in to comment.