If I have multiple incoming notifications, how do I limit the number that are visible ? Is there a property to set or is there a way I can programmatically remove certain toasts?
Thank you
1 Answer, 1 is accepted
0
Svetoslav Dimitrov
Telerik team
answered on 25 Nov 2022, 11:55 AM
Hello Tony,
You can introduce a counter in your application and increase its value in the method that calls the notifications. I have prepared a basic example of the concept and you can use it as a base for your application.
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Thank you for the suggestions on my previous question.
The scenario that I am looking to solve is if there are more than 5 notifications, show only the latest 5.
I currently am trying to add incoming notifications to a collection and then only show the last five.
When the following code runs:
I get the following error:
I there a way I can set different Key values?
Thanks,
Tony
Svetoslav Dimitrov
Telerik team
commented on 01 Dec 2022, 11:54 AM
Hello Tony,
To be really honest I am not sure why this exception is thrown. I modified my previous snippet so that it takes the last 5 notifications. Snippet workflow:
Click the Add a basic notification button. It will populate a collection of NotificaionModel with 25 notifications.
Click the Show Notifications button. It will reverse the collection of notifications and render only the last 5
Can you compare the snippet against your own and see if any differences are causing the issue? If this does not help you move forward, can you modify the snippet and send it back to me for further investigation?
<TelerikButton OnClick="@AddNotification">Add a basic notification</TelerikButton>
<TelerikButton OnClick="@ShowNotifications">Show Notifications</TelerikButton>
<TelerikNotification @ref="@NotificationReference" Class="MyTelerikNotification"></TelerikNotification>
@code {
public TelerikNotification NotificationReference { get; set; }
publicint NotificationCount = 0;
public List<NotificationModel> NotificationsContainer { get; set; } = new();
publicvoidAddNotification()
{
for (int i = 0; i <= 25; i++)
{
NotificationsContainer.Add(new NotificationModel()
{
Text = $"Auto Closable Notification {i}",
ThemeColor = ThemeConstants.Notification.ThemeColor.Primary
});
}
}
privatevoidShowNotifications()
{
var reversedNotifications = NotificationsContainer.Reverse<NotificationModel>().Take(5); //take last 5 notificationsforeach (var notification in reversedNotifications)
{
NotificationReference.Show(notification);
}
}
}
<style>
.MyTelerikNotification .k-notification-container .k-notification-wrap {
width: 300px;
height: 50px;
font-size: 1.5em;
text-align: center;
align-items: center;
}
</style>