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
toeknee10mo ago
You can technically just delete the notification directly so no need to clear?
tinkypinky
tinkypinkyOP10mo ago
How to access current notification within the Action?
toeknee
toeknee10mo ago
So you want to add a button to the popup notification to clear it?
tinkypinky
tinkypinkyOP10mo ago
Yes Not Popup but Database Notification
toeknee
toeknee10mo ago
But database notifications have an X to them to remove it?
LeandroFerreira
LeandroFerreira10mo 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
tinkypinkyOP10mo ago
This will close the modal. I want to delete it from the db.
LeandroFerreira
LeandroFerreira10mo ago
Where are you trying to do it?
tinkypinky
tinkypinkyOP10mo ago
From the Notification Modal
LeandroFerreira
LeandroFerreira10mo ago
Do you have the notification id?
tinkypinky
tinkypinkyOP10mo ago
Let me show you a little bit of code.
LeandroFerreira
LeandroFerreira10mo ago
I guess you can use in the action ->dispatch('notificationClosed', ['id' => 'notificationid'])
tinkypinky
tinkypinkyOP10mo 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
LeandroFerreira10mo ago
'x-on:click' => 'close' will delete the notification I guess. Try it
tinkypinky
tinkypinkyOP10mo ago
Perfect. How did you came to know about this? I mean where to look in docs etc.
LeandroFerreira
LeandroFerreira10mo ago
The Filament docs are awesome, but sometimes we gotta dive into the source code to get things done.
khairulazmi_
khairulazmi_6mo ago
can we totally remove clear button. ?
toeknee
toeknee6mo ago
You can use CSS, but if you are not purging them I would advise against it.
khairulazmi_
khairulazmi_6mo ago
I don't want user to clear their notifications . Just mark as read only..
toeknee
toeknee6mo ago
which is bad if they have 400 notifications you'll end up with browser slow downs.
khairulazmi_
khairulazmi_6mo ago
But if user mark as read, filament won't fetch it correct?
toeknee
toeknee6mo ago
Yes it will, it shows all notifications in the notification modal.
Want results from more Discord servers?
Add your server