search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Navigator for DayPilot Calendar with ViewType='Resources'

Asked by Nely
4 years ago.

Sorry if my grammar is not absolutely correct. I'm not a native speaker.

I need to navigate through a calendar with ViewType='Resources' like it was a ViewType='Day'. In my MVC controller I have created my columns like follows:

protected override void OnInit(InitArgs e)
{
var db = new DBContext();
Columns.Clear();
Column today = new Column(StartDate.ToShortDateString(), StartDate.ToString("s"));
today.Date = StartDate;
foreach (var user in db.Users.Where(u => u.Role == Role.Technician))
{
today.Children.Add(user.Name, Convert.ToString(user.UserId), StartDate);
}
Columns.Add(today);

FillCalendar();//here I upload my events from my database
Update(CallBackUpdateType.Full);

}

in my view I have the following:
@Html.DayPilotCalendar("dp_day", new DayPilotCalendarConfig
{
ViewType = DayPilot.Web.Mvc.Enums.Calendar.ViewType.Resources,
...
}

but when I click in my navigator, my calendar is not getting updated despite the StartDate in my OnCommand method is updated correctly.

Please I need your help!

Answer posted by Dan Letecky [DayPilot]
4 years ago.

If you click a date in the Navigator and you have linked it to the main Calendar using BoundDayPilot property it will fire OnCommand event:

@Html.DayPilotNavigator("dpn", new DayPilotNavigatorConfig { 
    // ...
    BoundDayPilot = "dpc"
    })

@Html.DayPilotCalendar("dpc", new DayPilotCalendarConfig
{
    ViewType = DayPilot.Web.Mvc.Enums.Calendar.ViewType.Resources,
    // ...
})

If you want to change the date of the Calendar you will need to handle OnCommand and reload the Columns there using the new date (it's available as e.Data["day"] in OnCommand).

It could look like this:

protected override void OnCommand(CommandArgs e) 
{ 
  if (e.Command == "navigate") {
    DateTime day = (DateTime) e.Data["day"];
    
    var db = new DBContext(); 
    Columns.Clear(); 
    Column today = new Column(day.ToShortDateString(), day.ToString("s")); 
    today.Date = day; 
    foreach (var user in db.Users.Where(u => u.Role == Role.Technician)) 
    { 
      today.Children.Add(user.Name, Convert.ToString(user.UserId), day); 
    } 
    Columns.Add(today);

    FillCalendar();//here I upload my events from my database 
    Update(CallBackUpdateType.Full);  
  }
}

See also:
https://doc.daypilot.org/calendar/navigator/

Answer posted by Nely
4 years ago.

Thanks a lot, I figure it out and my solution was pretty similar.

This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.