Loading icon displaying forever

Hello everyone,

I am developing a server side blazor application. 

When the scheduler first loads the icon is always displaying, when I change week or displaying I can see the events and the control works normally.

Here is my code:

Index.razor


@page "/"

<PageTitle>Index</PageTitle>

<SfSchedule @ref="ScheduleRef" TValue="Appointment" Height="100%" FirstDayOfWeek=1>
    <ScheduleEventSettings TValue="Appointment">
        <SfDataManager AdaptorInstance="@typeof(AppointmentAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
    </ScheduleEventSettings>
</SfSchedule>


Appointment adaptor:

using Microsoft.EntityFrameworkCore;

using Labo50.Data;
using Labo50.Data.Models;
using Syncfusion.Blazor;
using Syncfusion.Blazor.Data;
namespace Labo50.Adaptors;


public class AppointmentAdaptor : DataAdaptor
{
    private readonly IDbContextFactory<LaboDbContext> dbContextFactory;


    public AppointmentAdaptor(IDbContextFactory<LaboDbContext> dbContextFactory)
    {
        this.dbContextFactory = dbContextFactory;
    }


    public override object Read(DataManagerRequest dataManagerRequest, string? key = null)
    {
        var laboDbContext = dbContextFactory.CreateDbContext();
        IQueryable<Appointment> DataSource = laboDbContext.Appointments.AsQueryable();
        DataResult DataObject = new DataResult();
        if (dataManagerRequest.Search != null && dataManagerRequest.Search.Count > 0)
        {
            // Searching
            DataSource = DataOperations.PerformSearching(DataSource, dataManagerRequest.Search);
        }
        if (dataManagerRequest.Sorted != null && dataManagerRequest.Sorted.Count > 0)
        {
            // Sorting
            DataSource = DataOperations.PerformSorting(DataSource, dataManagerRequest.Sorted);
        }
        if (dataManagerRequest.Where != null && dataManagerRequest.Where.Count > 0)
        {
            // Filtering
            DataSource = DataOperations.PerformFiltering(DataSource, dataManagerRequest.Where, dataManagerRequest.Where[0].Operator);
        }
        int count = DataSource.Cast<Appointment>().Count();
        if (dataManagerRequest.Skip != 0)
        {
            //Paging
            DataSource = DataOperations.PerformSkip(DataSource, dataManagerRequest.Skip);
        }
        if (dataManagerRequest.Take != 0)
        {
            DataSource = DataOperations.PerformTake(DataSource, dataManagerRequest.Take);
        }
        // return dataManagerRequest.RequiresCounts ? new Syncfusion.Blazor.Data.DataResult() { Result = DataSource, Count = count } : DataSource;
        return dataManagerRequest.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : DataSource;
    }
    public override object Insert(DataManager dm, object value, string key)
    {
        //Orders.Insert(0, value as Order);
        //update changes in db
        var dbContext = dbContextFactory.CreateDbContext();
        var appointment = (Appointment)value;
        appointment.Id = 0;
        dbContext.Appointments.Add(appointment);
        dbContext.SaveChanges();
        return value;
    }
}



program.cs: 

builder.Services.AddScoped<AppointmentAdaptor>();

Any suggestions?

Thanks in advance!



3 Replies

RM Ruksar Moosa Sait Syncfusion Team April 27, 2022 01:59 PM UTC

Hi Lucio,


Thanks for the update.


We have checked the reported problem but unfortunately, we are not able to replicate the issue at our end. Could you please get back to us with the below details that help us to validate the issue further and provide the solution earlier?

  • Share the details of what we have missed in our sample to replicate the issue or
  • Replicate the issue in the attached sample if possible


Regards,

Ruksar Moosa Sait


Attachment: ScheduleSample_98170927.zip


LU Lucio April 28, 2022 09:27 AM UTC

Hi Ruksar,

I tried using the code provided but it's for a different framework, I am using Blazor.

I found a way to solve my issue:

In the adaptor, i use this code:


    public override async Task<object> ReadAsync(DataManagerRequest dataManagerRequest, string? key = null)

    {
        var laboDbContext = await dbContextFactory.CreateDbContextAsync();
        IQueryable<Appointment> DataSource = laboDbContext.Appointments.AsQueryable();
        DataResult DataObject = new DataResult();
        if (dataManagerRequest.Search != null && dataManagerRequest.Search.Count > 0)
        {
            // Searching
            DataSource = DataOperations.PerformSearching(DataSource, dataManagerRequest.Search);
        }
        if (dataManagerRequest.Sorted != null && dataManagerRequest.Sorted.Count > 0)
        {
            // Sorting
            DataSource = DataOperations.PerformSorting(DataSource, dataManagerRequest.Sorted);
        }
        if (dataManagerRequest.Where != null && dataManagerRequest.Where.Count > 0)
        {
            // Filtering
            DataSource = DataOperations.PerformFiltering(DataSource, dataManagerRequest.Where, dataManagerRequest.Where[0].Operator);
        }
        if (dataManagerRequest.Params != null && dataManagerRequest.Params.Count > 0)
        {
            if (dataManagerRequest.Params.ContainsKey("StartDate"))
            {
                var date = (DateTime)dataManagerRequest.Params["StartDate"];
                DataSource = DataSource.Where(a => a.StartTime >= date);
            }
            if (dataManagerRequest.Params.ContainsKey("EndDate"))
            {
                var date = (DateTime)dataManagerRequest.Params["EndDate"];
                DataSource = DataSource.Where(a => a.StartTime <= date);
            }
        }
        if (dataManagerRequest.Skip != 0)
        {
            //Paging
            DataSource = DataOperations.PerformSkip(DataSource, dataManagerRequest.Skip);
        }
        if (dataManagerRequest.Take != 0)
        {
            DataSource = DataOperations.PerformTake(DataSource, dataManagerRequest.Take);
        }


        if (dataManagerRequest.RequiresCounts)
        {
            var result = await DataSource.ToListAsync();
            return new DataResult() { Result = result, Count = result.Count };
        }
        else
        {
            // This works as intended:
            return await DataSource.ToListAsync();
            // This displays a loading icon forever:
            return DataSource.ToList();
        }
    }


I think in theory the 2 lines should be equal, but I must be missing something.

Thanks!



VM Vengatesh Maniraj Syncfusion Team replied to Lucio May 2, 2022 11:50 AM UTC

Hi Lucio,


Thanks for the update.

We are happy that you have found the solution.

We checked the problem and we suspect that the problem occurs due to the delaying of asynchronous success. Please let us know if you need any further assista


Regards,

Vengatesh 


Loader.
Up arrow icon