Clear Notification after Button Clicked

Is it possible to clear a specific database notification by clicking an action button?
Solution:
'x-on:click' => 'close' will delete the notification I guess. Try it
Jump to solution
22 Replies
toeknee
toeknee13mo ago
You can technically just delete the notification directly so no need to clear?
tinkypinky
tinkypinkyOP13mo ago
How to access current notification within the Action?
toeknee
toeknee13mo ago
So you want to add a button to the popup notification to clear it?
tinkypinky
tinkypinkyOP13mo ago
Yes Not Popup but Database Notification
toeknee
toeknee13mo ago
But database notifications have an X to them to remove it?
LeandroFerreira
LeandroFerreira13mo ago
this?
Notification::make()
->title('Saved successfully')
->success()
->actions([
\Filament\Notifications\Actions\Action::make('clear')
->label('Clear')
->extraAttributes([
'x-on:click' => 'close',
]),
])
Notification::make()
->title('Saved successfully')
->success()
->actions([
\Filament\Notifications\Actions\Action::make('clear')
->label('Clear')
->extraAttributes([
'x-on:click' => 'close',
]),
])
tinkypinky
tinkypinkyOP13mo ago
This will close the modal. I want to delete it from the db.
LeandroFerreira
LeandroFerreira13mo ago
Where are you trying to do it?
tinkypinky
tinkypinkyOP13mo ago
From the Notification Modal
LeandroFerreira
LeandroFerreira13mo ago
Do you have the notification id?
tinkypinky
tinkypinkyOP13mo ago
Let me show you a little bit of code.
LeandroFerreira
LeandroFerreira13mo ago
I guess you can use in the action ->dispatch('notificationClosed', ['id' => 'notificationid'])
tinkypinky
tinkypinkyOP13mo ago
If I click on clear, it deletes all notifications for the user. I want to delete only a specific notification after Download button is clicked
No description
Solution
LeandroFerreira
LeandroFerreira13mo ago
'x-on:click' => 'close' will delete the notification I guess. Try it
tinkypinky
tinkypinkyOP13mo ago
Perfect. How did you came to know about this? I mean where to look in docs etc.
LeandroFerreira
LeandroFerreira13mo ago
The Filament docs are awesome, but sometimes we gotta dive into the source code to get things done.
khairulazmi_
khairulazmi_9mo ago
can we totally remove clear button. ?
toeknee
toeknee9mo ago
You can use CSS, but if you are not purging them I would advise against it.
khairulazmi_
khairulazmi_9mo ago
I don't want user to clear their notifications . Just mark as read only..
toeknee
toeknee9mo ago
which is bad if they have 400 notifications you'll end up with browser slow downs.
khairulazmi_
khairulazmi_9mo ago
But if user mark as read, filament won't fetch it correct?
toeknee
toeknee9mo ago
Yes it will, it shows all notifications in the notification modal.

Did you find this page helpful?