Set column action on condition
I have a table of products. Now if the product is of type 'bundled product' I want to bind an action that when clicked on the product name (the
TextColumn
) a modal opens displaying the contents of the product bundle.
But if the product is not of type 'bundled' then you shouldn't be able to click the product name since there are no bundled products to display in the modal. So the action should not be attached in that case.
I've tried visible
, hidden()
on the action but they don't seem to work. Not when using a closure and not when passing in a hardcoded true
of false
value. The product name is always clickable and the action is executed.
Is it even possible to have the action conditionally set? How would I do that?
Thanks for any help and pointers.10 Replies
->visible(fn($record): bool => $record->product_type === ProductTypeEnum::BUNDLED->value)
?I've tried that, but the action is still there. As in, the column value is still clickable. Only the modal won
won't show up
how about
->action(fn ($record): bool => ($record->product_type === ProductTypeEnum::BUNDLED->value) ? Action::make(...)... : null
This doesn't work either. The action gets attached for either all rows in the column or for no rows. I don't think it's possible to conditionally set the action for a row?
it is possible
but you need to debug it
ive set you on the right track there
i cant debug for you
I know and I certainly appreciate your help. I've tried your solution with
But If I set that on my TextColumn and randomly return true of false - a different value per row - as a test, all rows follow the value of the first row. So if for example the first row returns false all rows will not have the action and if it returns true all rows will indeed have the action
try this, but also with
disableClick()
on the column itself doing the inverse conditionOr do i need to apply
->action()
not on my column but on something else?
ok thanks I will try it in a few minutes
Thanks this works, although on the rows that do not have an action they still visually appear as a link (orange and lighter orange on hover). I think this is because all these classes appear on filament-tables-text-column
:
filament-tables-text-column px-4 py-3 text-primary-600 transition hover:text-primary-500 hover:underline focus:text-primary-500 focus:underline
Is there any way to remove those when the row does not have the action attached?@jelmerkeij Hi. I'm having a very similar issue, I think, but at the early stages. I want an action if certain conditions are met, but only want to display plain old text if those conditions aren't met.
I will try to replicate what it sounds like you did, but I'll still eventually get to where I want to just display plain old text if the "actionable conditions" aren't met.
Were you able to find a good solution...? 🤔
Any help you can provide would be great. 🤓
Hai, Im also have this similar issue
did you got the solution ?