F
Filament15mo ago
mona

how to get filter state in v3?

in liveware how to design a filter and get its state ?
4 Replies
toeknee
toeknee15mo ago
How do you mean? You use filters as per the filters docs, where are you wanting to get the state?
mona
monaOP15mo ago
i have designed a filter inside liveware in filament-v2 and i was getting the state also inside getTableQuery() by using getTableFilters function (provided below) $month_selected = $this->getTableFilterState("attendance_month")["value"]; but after upgrading to v3 i am not getting filter state . to check i have provided some customized code like below inside filters of table in liveware . SelectFilter::make('attendance_month') ->options([ 'January' => 'January', 'February' => 'February', 'March' => 'March', ]), and then inside getTablequery function i have provide below code $month_selected = $this->table->getFilters(); after it when i tried to check dump($month_selected); i am getting below result instead of specific optioin which i have choosen. "attendance_month" => Filament\Tables\Filters\SelectFilter {#3379 ▶}
Skjena
Skjena15mo ago
I'm having the same problem also I've created a custom table widget, which extends from TableWidget, I'm using the following methods: getTableQuery() for designing the table query, getTableFilters() for setting up the table filter, and getTableColumns() for configuring the table columns. My goal is to access the current filter value within the getTableQuery() method to customize my query based on the filter selection and also determine the number of columns the table should return. However, I've encountered an issue where $this->tableFilters initially returns null and only contains the updated filter value after the filter has been modified. It appears that the filter is not set initially and only captures its value when a filter selection is made, resulting in $this->tableFilters always containing the previous value. While I can update the table widget successfully with the table filter value after the filter has been modified a second time, it still reflects the previous value. Is there a method or workaround to obtain the current filter value in this scenario?
Want results from more Discord servers?
Add your server