ejSchedule url DataManager on demand

Trying to get the scheduler to work with a remote datamanager using the url adapter and on demand data

the datamanager calls the web service and passes

CurrentDate
CurrentView
CurrentAction

the CurrentDate can be any date that is visible on screen. For example in a week view it could be pointing to Monday, Tuesday, Wednesday, Thursday, Friday, Saturday or Sunday.

that doesn't make sense. Now the web service would have to try and figure out what days are visible based on that date and send the data.

what it should do is to ask for specific dates that data is needed for. Either ask for each date separately or send an array of dates. This would also allow a caching mechanism to only request data from the server for days it hasn't requested them for




3 Replies

KK Karthigeyan Krishnamurthi Syncfusion Team October 12, 2017 08:48 AM UTC

Hi Michael, 
 
Thank you for contacting Syncfusion support. 
 
In Load on demand concept, Scheduler current date is passed to the controller where the current view range will be calculated, and appointments will be filtered based on that range. Range calculation and filtering process are done in Models-> AppointmentRepository.cs file as shown below. We have prepared the LOD CRUD sample for your reference which can be download from the below location. 
 
In the above sample, during the initial load, view change, and performing any CRUD action will call GetData function to filter only the current view range appointments. It is the default behavior and currently there is no option to send array of dates. 
 
<Code> 
public ActionResult GetData(string CurrentView, DateTime CurrentDate, string CurrentAction) 
{ 
    var data = AppointmentRepository.FilterAppointment(CurrentDate, CurrentAction, CurrentView); 
    BatchDataResult result = new BatchDataResult(); 
    result.result = data;           
    result.count = db.Appointments.ToList().Count > 0 ? db.Appointments.ToList().Max(p => p.Id) : 1; 
    return Json(result, JsonRequestBehavior.AllowGet); 
} 
 
public static List<Appointment> FilterAppointment(DateTime CurrentDate, String CurrentAction, String CurrentView) 
{ 
    ScheduleDataDataContext db = new ScheduleDataDataContext(); 
    DateTime CurrDate = Convert.ToDateTime(CurrentDate); 
    DateTime StartDate = FirstWeekDate(CurrDate.Date); 
    DateTime EndDate = FirstWeekDate(CurrDate.Date); 
    List<Appointment> DefaultScheduleList = db.Appointments.ToList(); 
    switch (CurrentView) 
    { 
        case "day": 
            StartDate = CurrentDate; 
            EndDate = CurrentDate.AddHours(24); 
            break; 
        case "week": 
            EndDate = EndDate.AddDays(7); 
            break; 
        case "workweek": 
            EndDate = EndDate.AddDays(5); 
            break; 
        case "month": 
            StartDate = CurrDate.Date.AddDays(-CurrDate.Day + 1); 
            EndDate = StartDate.AddMonths(1); 
            break; 
        case "agenda": 
            EndDate = EndDate.AddDays(7); 
            break; 
    } 
    DefaultScheduleList = db.Appointments.ToList().Where(app => app.StartTime >= StartDate && app.StartTime <= EndDate || app.Recurrence==true).ToList();// here particular date DefaultSchedule is filtered 
    return DefaultScheduleList; 
} 
 
internal static DateTime FirstWeekDate(DateTime CurrentDate) 
{ 
    try 
    { 
        DateTime FirstDayOfWeek = CurrentDate; 
        DayOfWeek WeekDay = FirstDayOfWeek.DayOfWeek; 
        switch (WeekDay) 
        { 
            case DayOfWeek.Sunday: 
                break; 
            case DayOfWeek.Monday: 
                FirstDayOfWeek = FirstDayOfWeek.AddDays(-1); 
                break; 
            case DayOfWeek.Tuesday: 
                FirstDayOfWeek = FirstDayOfWeek.AddDays(-2); 
                break; 
            case DayOfWeek.Wednesday: 
                FirstDayOfWeek = FirstDayOfWeek.AddDays(-3); 
                break; 
            case DayOfWeek.Thursday: 
                FirstDayOfWeek = FirstDayOfWeek.AddDays(-4); 
                break; 
            case DayOfWeek.Friday: 
                FirstDayOfWeek = FirstDayOfWeek.AddDays(-5); 
                break; 
            case DayOfWeek.Saturday: 
                FirstDayOfWeek = FirstDayOfWeek.AddDays(-6); 
                break; 
        } 
        return (FirstDayOfWeek); 
    } 
    catch 
    { 
        return DateTime.Now; 
    } 
} 
</Code> 
 
Regards, 
Karthigeyan 




MS Michael Salzlechner October 12, 2017 12:36 PM UTC

that's not a very smart design for a number of reasons

1) First Day of the week
the webservice doesn't know what the first day of week is as shown in the control as it can be changed. So realistically the server cannot properly calculate the days for a weekly

2) Days defined in a workweek display
the control allows to only show certain days in a workweek. it isn't always 5. again the webservice doesn't know this

3) Agenda Display
the control allows showing multiple weeks. The webservice wouldn't know that

it would be smarter for the control to request the exact dates needed in an array for example. This would solve all these issues and would also allow the control to implement smart caching by only requesting dates it really needs data for.

All of the above also applies to the navigation events of course. These are not as bad because we can do the workaround coding in javascript but it is still unnecessary




KK Karthigeyan Krishnamurthi Syncfusion Team October 17, 2017 01:33 PM UTC

Hi Michael,  
 
Thanks for your valuable suggestion. 
 
We would like to inform that currently there is no option to achieve your requirement in Load on demand concept.  
 

Regards, 
Karthigeyan 



Loader.
Up arrow icon