F
Filament8mo ago
Patie

Table update after action

Hi, im using filament as livewire components without full panel. On user detail page I have user infolist component - there is section with headerActions (form for adding user documents) and user document table inside schema.
Section::make('Documents')
->id('documents')
->headerActions([
Action::make('Add document')
->form($this->userDocumentForm->schema())
->action(function (array $data, User $user) {
$this->userDocumentForm->action($data, $user);
})
])
->schema([
Livewire::make(UserDocumentTable::class, ['userId' => $this->user->id])->key('user-document-table'),
]),
Section::make('Documents')
->id('documents')
->headerActions([
Action::make('Add document')
->form($this->userDocumentForm->schema())
->action(function (array $data, User $user) {
$this->userDocumentForm->action($data, $user);
})
])
->schema([
Livewire::make(UserDocumentTable::class, ['userId' => $this->user->id])->key('user-document-table'),
]),
what is correct way to update user document table to show updated data after create (or edit/delete) in my case? thank you!
8 Replies
awcodes
awcodes8mo ago
Dispatch a refresh to your livewire component.
Patie
PatieOP8mo ago
refresh whole component is only (correct) way when using standalone components? there is no way to reload only data on filament table or smth like this? thank you @awcodes
awcodes
awcodes8mo ago
Unless you have nested components then you have to refresh the whole component. Technically you shouldn’t have to if the data changes. The data change should just automatically do a rerender. Maybe also look into computed properties in livewire.
Patie
PatieOP8mo ago
not automatically re-rendered in my case, probably i have something wrong probably bcs i have it as Livewire::make 🤔 im using
->schema([
Livewire::make(UserDocumentTable::class, ['userId' => $this->user->id])->key('user-document-table'),
]),
->schema([
Livewire::make(UserDocumentTable::class, ['userId' => $this->user->id])->key('user-document-table'),
]),
because i want reuse existing table code, is there better way how to do it maybe?
awcodes
awcodes8mo ago
You should be able to dispatch a refresh to that specific component. Check out the livewire docs A computed property for the user might be better though.
Patie
PatieOP8mo ago
yes, emitting on whole component is working ofc, thx computed property probably should be on documents as table showing documents in rows, user is only for filtering
awcodes
awcodes8mo ago
Yea. Makes sense though. You need table to refresh and the main component is in charge of the table.
Patie
PatieOP8mo ago
hmm is strage dispatch not working from inside of
$this->userDocumentForm->action($data, $user);
$this->userDocumentForm->action($data, $user);
method, but only when its directly fired from action like this:
Section::make('Documents')
->id('documents')
->headerActions([
Action::make('Add document')
->form($this->userDocumentForm->schema())
->action(function (array $data, User $user) {
$this->userDocumentForm->action($data, $user);
$this->dispatch('user-document-created');

})
])
->schema([
Livewire::make(UserDocumentTable::class, ['userId' => $this->user->id])->key('user-document-table'),
]),
Section::make('Documents')
->id('documents')
->headerActions([
Action::make('Add document')
->form($this->userDocumentForm->schema())
->action(function (array $data, User $user) {
$this->userDocumentForm->action($data, $user);
$this->dispatch('user-document-created');

})
])
->schema([
Livewire::make(UserDocumentTable::class, ['userId' => $this->user->id])->key('user-document-table'),
]),
but i understand its more like livewire problem and not filament it's a pity that there is no way to insert the form from another file like nested component into section section (or into tab directly) and must be used Livewire here
Want results from more Discord servers?
Add your server