livewire-datatables
livewire-datatables copied to clipboard
Feature Request: set default values to filters
is it possible to add a method that set a default value to a filter?
Column::name('name')->filterable()->filterDefault('John')
DateColumn::name('date')->filterable()->filterDefault(['start' => '1970-01-01', 'end' => '1970-12-31')
You can do this Inside builder method:
$this->activeSelectFilters[9][0] = "Default value";
*Replace "9" with the appropriate column number
You can do this Inside builder method:
$this->activeSelectFilters[9][0] = "Default value";
*Replace "9" with the appropriate column number
The results are then properly filtered by the new defaults but those default settings are not displayed in the header row. I tried to call $this->refreshLivewireDatatable() with no luck.
I did it with redefining mount() function.
Something like:
public function mount(
$model = null,
$include = [],
$exclude = [],
$hide = [],
$dates = [],
$times = [],
$searchable = [],
$sort = null,
$hideHeader = null,
$hidePagination = null,
$perPage = 10,
$exportable = false,
$hideable = false,
$beforeTableSlot = false,
$afterTableSlot = false,
$params = []
)
{
parent::mount($model,
$include,
$exclude,
$hide,
$dates,
$times,
$searchable,
$sort,
$hideHeader,
$hidePagination,
$perPage,
$exportable,
$hideable,
$beforeTableSlot,
$afterTableSlot,
$params);
$this->activeBooleanFilters[4] = "1";
}
You can do this Inside builder method:
$this->activeSelectFilters[9][0] = "Default value";
*Replace "9" with the appropriate column number
The results are then properly filtered by the new defaults but those default settings are not displayed in the header row. I tried to call $this->refreshLivewireDatatable() with no luck.
I have the same issue, no filter set visible and I also get an error when selecting others and deselecting the default one.
You can also set the appropriate property inside your table class. For example:
public $activeBooleanFilters = [
3 => 1,
4 => 0
];
public activeSelectFilters = [
9 => ["Default value"]
];
Set you defaults on mount():
public $activeBooleanFilters = [];
public $mount() { $this->activeBooleanFilters[4] = "1"; }
Then wire:model the control to the activeFilter you had setted the defaults to:
+1 This would be a really nice addition.
+1
How to use this please give a demo code on builder thanks
@amit-viacon
Hey guys. I have added this Feature. Would love to have your feedback on it.
Refs #527