sm
Dynamically defining a table's columns.
Hey there. I have a custom table widget which is linked to a custom field, which allows me to create dynamic tables in forms.. this has been working fine for a while. I wanted to try modifying the table's columns based on the current activetab, this almost works.. except it looks like the table() is rendered with a slightly out of sync $activeTab. Basically, if I click on the tab twice, it updates to the right columns, if not, it stays at the last active tab's columns. This isn't an issue on the ->query method because we can just pass a Closure there.. is there something similar that can done for table columns?
Thanks!
2 replies
Adding an action to a repeater.
Hey there,
I have a repeater that's displaying images using a Placeholder.. I'd like to allow users to select an image from the repeater, but:
Placeholder's don't accept suffix actions
if I just use Actions::make([]) inside the repeater schema, the actions are all the same action (i.e, triggering one triggers them all) since they're attached to the form.
What's the right way to add an action to a repeater so its displayed alongside its items?
4 replies
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
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!5 replies
Forcing a TableWidget to refresh its builder query.
Hey there!
I'm trying to figure out the best way to handle this:
I have a Resource with a form that has some filters, the filters apply to an unrelated model (i.e, not the Model associated with that form). Users can add/remove filters using a Repeater. I'd like to show them the results of applying the filters, so I decided to use a simple
ViewField
to load a "dynamic" TableWidget, basically it shows the data from the other model (it's super simple, just extending TableWidget). The blade for the viewfield looks like:
The table()
in the DynamicTableWidget
is:
When users update the filters on the main form, I'd like to pass a new builder (with those filters applied) to the table and force it to refresh.. any ideas?3 replies
Add dehydrateStateUsing to Builder\Block
I have a builder that I'm using to store related data on a Form, adding a
dehydrateStateUsing
to the builder works, but I want to have each block manage it's own dehydrated state to keep things a little bit more modular.. but adding a dehydrateStateUsing
to the Block doesn't seem to work (never gets called). I've also tried accessing ->blocks() and running getState() on them within the builder, but that doesn't trigger the dehydrateStateUsing callback either. The docs state that whenever getState()
is called the dehydrateStateUsing is called.. but that doesn't seem to be the case for Blocks? Any pointers?10 replies
Integrating with Livewire/Laravel eventing.
Hey guys,
I was wondering if anyone could point me to docs/source on how filament integrates with livewire eventing? For example, if I have a TableWidget that's included via a ViewComponent and fire an event from an action within the TableWidget (for example: a select action), I can't seem to listen for that event from the parent Form. I've tried just adding a
protected $listeners = ['eventName' => 'someFunc'];
and setting $this->data
from there, but the event doesn't seem to get through (is this something to do with emit direction?).
Also, it doesn't seem like I can use $this->emit() on form component closures, even though Filament uses livewire under the hood, is that expected? What's the right way to dispatch an event? is it using dispatchEvent
from a closure to which we pass the current instance?
Thanks!7 replies
Using ->multiple() on a Select inside a repeatable with ->options() results in a JS error.
I've got a Select with ->multiple()->options(function() { }) inside a repeatable, when I add and delete repeatables, it looks like state gets messed up (an empty item gets added back the next time I click add, i.e, instead of 1 new repeatable, I get two). There's no way to remove repeatables at this point (all deletes just re-appear).
After the first delete operation, I see an error with the
Select
component in the console:
Any help would be appreciated!4 replies