Scheduler hide/show appointments on button click

Hello,
I'm trying to make a button that shows/hides appointments with a specific boolean property setted to true from the scheduler.

This is what I tried:

private async Task ShowDone(bool show)
{
        if (show)
        {
            // Show hidden appointments
            ViewModel.Appointments = ViewModel.Appointments.Concat(ViewModel.EventsDone).ToList();
            ViewModel.EventsDone.Clear();
            _schedule.Refresh();
        }
        else
        {
            // Hide appointments
            ViewModel.EventsDone = ViewModel.Appointments.Where(x => x.IsDone).ToList();
            ViewModel.Appointments = ViewModel.Appointments.Except(ViewModel.EventsDone).ToList();
            _schedule.Refresh();
        }
}

Where ViewModel.Appointments is the list setted as source of the scheduler, on click it should remove/hide events with IsDone==true and show them when clicked again, the appointment model is the following:

 public class AppointmentModel
{
        public int Id { get; set; }
        public string Subject { get; set; }
        public string Location { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
        public string Description { get; set; }
        public bool IsDone { get; set; }
        public virtual string ElementType { get; set; }
}

This sometimes works and sometimes no, I can't understand why, and sometimes throws the following exception (but blazor still works):

System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at Microsoft.JSInterop.JSRuntime.InvokeWithDefaultCancellation[T](String identifier, Object[] args)
   at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, String identifier, Object[] args)
   at Syncfusion.Blazor.SfBaseComponent.InvokeMethod(String methodName, Object[] methodParams)
   at Syncfusion.Blazor.Popups.SfDialog.ComponentDispose()
   at System.Threading.Tasks.Task.<>c.b__139_0(Object state)
   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.ExecuteSynchronously(TaskCompletionSource`1 completion, SendOrPostCallback d, Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.ExecuteBackground(WorkItem item)


Other details:
- View: month
- Version: 18.2.44 and 18.2.45

I'm looking for a way to do this correctly, maybe Syncfusion knows a cleaner method to avoid these problems.

Thank you.

8 Replies 1 reply marked as answer

HB Hareesh Balasubramanian Syncfusion Team July 20, 2020 12:19 PM UTC

Hi Fabrizio, 

Greetings from Syncfusion Support..! 

We have validated your shared query “on click it should remove/hide events with IsDone==true and show them when clicked again” at our end. And we suspect that your requirement is to show/hide the particular events (IsDone filed) based on the button click. And for that, we have prepared a sample using eventRendered Scheduler events. 

Code snippet: 
<SfButton CssClass="e-flat" IsToggle="true" IsPrimary="true" @ref="ToggleButton" @onclick="OnToggleClick">Click</SfButton> 
<SfSchedule @ref="ScheduleRef" TValue="AppointmentData" Height="550px" SelectedDate="@(new DateTime(2020, 1, 6))"> 
    <ScheduleEventSettings DataSource="@DataSource"></ScheduleEventSettings> 
    <ScheduleEvents TValue="AppointmentData" EventRendered="EventRendered"></ScheduleEvents> 
</SfSchedule> 
 
@code{ 
    SfButton ToggleButton; 
    SfSchedule<AppointmentData> ScheduleRef; 
    public bool flag = false; 
    public void OnToggleClick(MouseEventArgs args) 
    { 
        if (flag) 
        { 
            flag = false; 
            ScheduleRef.RefreshEvents(); 
        } else 
        { 
            flag = true; 
            ScheduleRef.RefreshEvents(); 
        } 
    } 
    public void EventRendered(EventRenderedArgs<AppointmentData> args) 
    { 
        if (args.Data.IsDone && flag) 
        { 
            args.Cancel = true; 
        } 
    } 
} 


Kindly try the above solution and get back to us if you need any further assistance. 

Regards, 
Hareesh 


Marked as answer

FA Fabrizio Alessandro July 28, 2020 02:25 PM UTC

Thank you Hareesh this is great!


VM Vengatesh Maniraj Syncfusion Team July 29, 2020 04:15 AM UTC

Hi Fabrizio, 

You are most welcome. 

Please get in touch with us if you need any further assistance. 

Regards, 
Vengatesh  



FA Fabrizio Alessandro November 25, 2020 06:47 PM UTC

Hello,

I've just updated your sample to version 18.3.51 and it doesn't work anymore.

To reproduce the problem:
  • Run the sample and see the events on the scheduler
  • Click on the button on the top of the scheduler to hide the events with the property IsDone=true
  • See that these events are hidden correctly
  • Click on the button on the top of the scheduler to re-show the events with the property IsDone=true
  • See that these events do not appears in the scheduler (they should be visible at this point)

In the attachments there is the updated sample.
Tested with 18.3.50 and 18.3.51.

Thank you

Attachment: Scheduler_8c788728.zip


NR Nevitha Ravi Syncfusion Team November 26, 2020 10:33 AM UTC

Hi Fabrizio, 

Thanks for your update, 

We could replicate the reported problem “appointments not re-rendering again to the scheduler” at our end and confirm this as defect. We have logged the bug report for the issue which can be tracked from the following link. 

The issue fix will be included in our weekly patch release scheduled on December 1, 2020 and we would appreciate your patience until then. 

Regards, 
Nevitha 



NR Nevitha Ravi Syncfusion Team December 2, 2020 05:59 AM UTC

Hi Fabrizio, 

Thanks for being patience. 

We have resolved the reported issue “appointments are not re-rendering again to the scheduler” in our last weekly patch release v18.3.52. Please upgrade to avail the fix. 


Please get back to us if you need any further assistance. 

Regards, 
Nevitha 



FA Fabrizio Alessandro December 7, 2020 12:11 PM UTC

Thank you I can confirm this problem is solved.


NR Nevitha Ravi Syncfusion Team December 8, 2020 03:37 AM UTC

Hi Fabrizio, 

Thanks for your update. 

We are glad that our fix solved your issue, please get back to us if you need any further assistance. 

Regards, 
Nevitha 


Loader.
Up arrow icon