TableWidget interactions with livewire events.
Hey there,
I'm trying to understand how tablewidgets interact with livewire events.
My structure is: Resource that has a custom field, which renders a tablewidget through livewire.
The resource has an event defined in its
The
The
The TableWidget has an
This is where things get a bit funky: after that event is fired, the table widget's
My understanding is that
Any pointers?
Thanks!
I'm trying to understand how tablewidgets interact with livewire events.
My structure is: Resource that has a custom field, which renders a tablewidget through livewire.
The resource has an event defined in its
EditResource, and the TableWidget has an event defined in it (both using On attribute).The
table($table) function on the TableWidget has default query builder, basically modelClass::query(). It also has an Action, which fires an event which the EditResource is listening for. All of this works fine.The
Resource has a set of filters (not filament filters, custom filters built using a form component). When these are updated, the Resource fires an event which the TableWidget listens for in a func called updateFilters. The updateFilters func receives the filters from the event, and updates the TableWidget's query (by doing $this->query(modelClass::getFiltersFromEventData($filters));).. this works.The TableWidget has an
Add action attached to it, this just fires a livewire event (on $livewire) to indicate to the resource that a new record has been selected by the user. This is the event that the function in EditResource listens for, it attaches the selected record (using the id from the event) to the resource's modelClass.This is where things get a bit funky: after that event is fired, the table widget's
table($table) func gets called again, which resets the query builder (because it has ->query(modelClass::query())), resetting all the filters..My understanding is that
table($table) would only be called once on initialization, is this not the case? How can I preserve the Builder? I've tried adding a protected $filtersState to the TableWidget, but that causes all kinds of weird race conditions.. and I feel like I'm missing something obvious.Any pointers?
Thanks!