Tricks

Set or reset filters when searching in table

Oct 22, 2022
studiowizjo
Admin panel, Table builder

Sometimes you may want to set or reset filters when you are searching in table, eg. by default your table shows only not archived data or data from current month, but when searching you would like to include all records.

To do that you can place following code in your ListRecords page:

public function updatedTableSearchQuery() : void
{
if (blank($this->tableSearchQuery)) {
// reset filters to default
$this->tableFilters['not_finished']['isActive'] = true;
$this->tableFilters['finished']['isActive'] = false;
 
return;
}
 
// set your filters as you need
$this->tableFilters['not_finished']['isActive'] = true;
$this->tableFilters['finished']['isActive'] = true;
}

No comments yet…