SFcalendar not updating

I have an agenda view where I delete a cell and it doesn't update, I have the following xaml:

 <syncfusion:SfCalendar x:Name="Calendar" NumberOfWeeksInView="1" FirstDayofWeek="1"

                              ShowLeadingAndTrailingDays="True" AgendaViewHeight="300" ShowInlineEvents="True" InlineViewMode="Agenda" InlineItemTapped="Calendar_InlineItemTapped" />


I use FireBase to fill the events, and it shows them to me without problem in the calendar but when I delete a record from the database I don't know how to tell the calendar to reload its appointments



9 Replies

SS SaiGanesh Sakthivel Syncfusion Team April 5, 2023 12:14 PM UTC

Hi Juan,


#Regarding delete the appointments in the SfCalendar

We suggest that you remove the appointment from the view model collection after removing it from the Firebase database. This way, the change will be reflected in the view immediately. Please refer to the following code snippet for your reference.


Code snippet

private async void btnDelete_Clicked(object sender, EventArgs e)

{

    var appointment = viewmodel.Appointments[0];

    await firebaseHelper.DeleteEvent(appointment.Subject);

    await DisplayAlert("Success", "Event Deleted Successfully", "OK");

    viewmodel.Appointments.Remove(appointment);

}


Please refer to the demo sample in the attachment. Please let us know if you have any concerns.


Regards,
SaiGanesh Sakthivel


Attachment: CalendarXamarin_c9b0ded2.zip


JF Juan Francisco April 5, 2023 04:28 PM UTC

It works correctly, I delete an item from the calendar and it disappears, but if I re-enter a new item it doesn't update.



SS SaiGanesh Sakthivel Syncfusion Team April 6, 2023 08:58 AM UTC

Hi Juan,


#Regarding add new appointment and update in the SfCalendar

We suggest that you add the new item to the view model collection along with the FireBase Database. This way, the change will be reflected in the view immediately. Please refer to the following code snippet for your reference.


Code snippet

private async void newItem_Clicked(object sender, EventArgs e)

{

    DateTime today = DateTime.Now.Date;

    var appointment = new CalendarInlineEvent() { StartTime = today.AddHours(16), EndTime = today.AddHours(17), Subject = "new Meeting" };

    viewmodel.Appointments.Add(appointment);

    await firebaseHelper.AddEvents(appointment.StartTime, appointment.EndTime, appointment.Subject);

}


Please refer to the demo sample in the attachment. Please let us know if you have any concerns.


Regards,
SaiGanesh Sakthivel


Attachment: CalendarXamarin_6b8a6554.zip


JF Juan Francisco April 11, 2023 11:13 AM UTC

I have the following method that is launched at the beginning of starting the app and that inserts all the appointments that I have in firebase into the calendar.


Everything worked OK.


But when I delete something in Firebase and add a new appointment I need the calendar to be refreshed, calling the first method again to have it insert all the appointments again doesn't refresh the calendar.



public async void InsertReservaCal( string horaSelected)
        {
            colorCollection = new ObservableCollection<Color>();
            colorCollection.Add(Color.FromHex("#FFA2C139"));
            colorCollection.Add(Color.FromHex("#FFD80073"));
            colorCollection.Add(Color.FromHex("#FF1BA1E2"));
            colorCollection.Add(Color.FromHex("#FFE671B8"));
            colorCollection.Add(Color.FromHex("#FFF09609"));
            colorCollection.Add(Color.FromHex("#FF339933"));
            colorCollection.Add(Color.FromHex("#FF00ABA9"));
            colorCollection.Add(Color.FromHex("#FFE671B8"));
            colorCollection.Add(Color.FromHex("#FF1BA1E2"));
            colorCollection.Add(Color.FromHex("#FFD80073"));
            colorCollection.Add(Color.FromHex("#FFA2C139"));
            colorCollection.Add(Color.FromHex("#FFA2C139"));
            colorCollection.Add(Color.FromHex("#FFD80073"));
            colorCollection.Add(Color.FromHex("#FF339933"));
            colorCollection.Add(Color.FromHex("#FFE671B8"));
            colorCollection.Add(Color.FromHex("#FF00ABA9"));


            Mreservas parametros = new Mreservas();
            VMusuarios funcion = new VMusuarios();


            var data = (await Constantes.firebase
                 .Child("reservas")
                 .OnceAsync<Mreservas>()).Where ( a=> a.Object.Hora == horaSelected);
            foreach (var item in data)
            {
                parametros.Hora = item.Object.Hora;


                var appointment = new CalendarInlineEvent();
                var random = new Random();
                appointment.Subject = item.Object.Nombre + " " + item.Object.Ape;
                appointment.Color = colorCollection[random.Next(10)];
               
                int horas = Convert.ToInt16(item.Object.Hora.Substring(0, 2));
                int minutos = Convert.ToInt16(item.Object.Hora.Substring(3, 2));
                DateTime time = item.Object.Fecha.AddHours(Convert.ToInt16(horas)).AddMinutes(minutos);
                appointment.StartTime = Convert.ToDateTime(time.ToString("dd-MM-yyyy HH:mm"));
                appointment.EndTime = appointment.StartTime.AddHours(1);
                this.appointments.Add(appointment);
            }
        }


SS SaiGanesh Sakthivel Syncfusion Team April 12, 2023 11:45 AM UTC

Hi Juan,


#Regarding refresh the items in the SfCalendar

We suggest that you clear the viewmodel collection and retrieve the item from the FireBase Database and add to the viewmodel collection to refresh the UI. Please refer to the following code snippet for your reference.


Code snippet

private async void Refresh_Clicked(object sender, EventArgs e)

{

    var Appointments = await firebaseHelper.GetAllEvents();

    viewmodel.Appointments.Clear();

    foreach (var appointment in Appointments)

    {

        viewmodel.Appointments.Add(new CalendarInlineEvent() { StartTime = appointment.StartTime, EndTime = appointment.EndTime, Subject = appointment.Subject });

    }

}


Please refer to the demo sample in the attachment. Please let us know if you have any concerns.


Regards,
SaiGanesh Sakthivel


Attachment: CalendarXamarin_ec55cd8b.zip


JF Juan Francisco June 28, 2023 07:20 AM UTC

I don't want a button to update the calendar.


I want that when a day is clicked its events will come out.


Currently when you load the form it appears marked today. But with no events, I have to mark any other day and go back to today again for everything to load.



MS Muniappan Subramanian Syncfusion Team June 29, 2023 10:43 AM UTC

Juan,


Based on the information you provided regarding your query, 'I want that when a day is clicked, its events will be displayed,' we have conducted a thorough investigation. If you prefer not to refresh the calendar by clicking a button, you can fetch the appointment data initially. We have updated the sample accordingly. Please find the attached sample.


If the provided information does not meet your requirements, kindly revert to us with more details. This will helpful for us to provide you with a better solution.


Regards,

Muniappan S


Attachment: CalendarXamarin_28d9ea2d.zip


JF Juan Francisco June 29, 2023 03:26 PM UTC

OK thank you very much, all perfect!



SS SaiGanesh Sakthivel Syncfusion Team June 30, 2023 01:00 PM UTC

Juan,


We are glad to know that the provided solution is resolved the query. Please let us know if you need any further assistance on this. 


Loader.
Up arrow icon