F
Filament14mo ago
Antoine

Actions in renderHooks

Hello everyone, I'm trying to return an array of actions in a view that I return through a renderHooks.
public function getViews()
{
return[
Action::make('table')
->action(function() {
dd();
}),
Action::make('list')
->action(function() {
dd();
}),
];
}
public function getViews()
{
return[
Action::make('table')
->action(function() {
dd();
}),
Action::make('list')
->action(function() {
dd();
}),
];
}
@props([
'views' => $this->getViews(),
])

@if ($multipleViews)
<x-filament-tables::actions
:actions="$views"
/>
@endif
@props([
'views' => $this->getViews(),
])

@if ($multipleViews)
<x-filament-tables::actions
:actions="$views"
/>
@endif
My buttons display correctly but do not trigger the action() methods. Anyone know why?
3 Replies
Antoine
AntoineOP14mo ago
It seems that my problem is linked to an action name and function name. If I do it this way, it works but I multiply the functions which I don't like:
public function tableAction(): Action
{
return Action::make('table')
->action(function() {
dd();
});
}

public function listAction(): Action
{
return Action::make('list')
->action(function() {
dd();
});
}

public function getViews()
{
return [
$this->listAction(),
$this->tableAction(),
];
}
public function tableAction(): Action
{
return Action::make('table')
->action(function() {
dd();
});
}

public function listAction(): Action
{
return Action::make('list')
->action(function() {
dd();
});
}

public function getViews()
{
return [
$this->listAction(),
$this->tableAction(),
];
}
If I name a function with a name different from the action name. It doesn't work anymore but my view show correctly but not the method action() :
public function tableAction(): Action
{
return Action::make('newNameTable')
->action(function() {
dd();
});
}
public function tableAction(): Action
{
return Action::make('newNameTable')
->action(function() {
dd();
});
}
awcodes
awcodes14mo ago
The actual function name is important when trying to default render them in the component. It has to have ‘Action’ on the method name to be able to render.
Antoine
AntoineOP14mo ago
I understand. Is there a method to specify the function name to be interpreted? Something like this:
public function getViews()
{
return[
Action::make('table')
->actionName('tableAction')
->action(function() {
dd();
}),
Action::make('list')
->actionName('listAction')
->action(function() {
dd();
}),
];
}
public function getViews()
{
return[
Action::make('table')
->actionName('tableAction')
->action(function() {
dd();
}),
Action::make('list')
->actionName('listAction')
->action(function() {
dd();
}),
];
}
Otherwise do you know in which method the nameAction() are registered to understand how it works?
Want results from more Discord servers?
Add your server