DayPilot Scheduler allows automatic event reloading (in specified intervals).
AutoRefresh is disabled by default. You can enable it using AutoRefreshEnabled property.
If enabled, AutoRefresh will fire Command event on the server side with the value of AutoRefreshCommand as the command name.
Configuration properties:
-
AutoRefreshEnabled (bool)
-
AutoRefreshInterval (int) - number of seconds between automatic reloads
-
AutoRefreshMaxCount (int) - maximum number of automatic reloads
-
AutoRefreshCommand (string) - a command value that will be passed to Command event when requesting a reload
AutoRefresh is paused automatically during drag and drop operations (event moving, resizing, time range selecting, row moving, etc.).
JavaScript
If enabled using autoRefreshEnabled property, it will fire onAutoRefresh event in the specified intervals.
dp.autoRefreshInterval = 10;
dp.autoRefreshMaxCount = 10;
dp.autoRefreshEnabled = true;
dp.onAutoRefresh = function(args) {
dp.events.load("/getEvents");
};
Use .autoRefreshPause() and .autoRefreshStart() to pause and resume the autorefresh during long UI interactions, such as a modal dialog (available since build 8.1.1760).
See also .events.load() method.
ASP.NET WebForms
.aspx
<DayPilot:DayPilotScheduler
ID="DayPilotScheduler1"
runat="server"
...
OnCommand="DayPilotScheduler1_Command"
AutoRefreshEnabled="true"
AutoRefreshInterval="10"
AutoRefreshMaxCount="12"
/>
.aspx.cs
protected void DayPilotScheduler1_Command(object sender, DayPilot.Web.Ui.Events.CommandEventArgs e)
{
switch (e.Command)
{
case "refresh":
setDataSourceAndBind();
DayPilotScheduler1.DataBind();
DayPilotScheduler1.UpdateWithMessage("Events refreshed automatically");
break;
default:
throw new Exception("Unknown command.");
}
}
Demo
ASP.NET MVC
View
@Html.DayPilotScheduler("dps", new DayPilotSchedulerConfig()
{
BackendUrl = ResolveUrl("~/Scheduler/Backend"),
...
AutoRefreshEnabled = true,
AutoRefreshInterval = 10,
AutoRefreshMaxCount = 5
})
Controller
protected override void OnCommand(CommandArgs e)
{
switch (e.Command)
{
case "refresh":
UpdateWithMessage("Refreshed");
break;
}
}
protected override void OnFinish()
{
// only load the data if an update was requested by an Update() call
if (UpdateType == CallBackUpdateType.None)
{
return;
}
DateTime start = StartDate;
DateTime end = StartDate.AddDays(Days + 1);
Events = new EventManager(Controller).FilteredData(start, end).AsEnumerable(); // your method for loading events
DataStartField = "start";
DataEndField = "end";
DataTextField = "text";
DataIdField = "id";
DataResourceField = "resource";
}
Demo
The demo page refreshes the events every 10 seconds for 2 minutes (maximum 12 times):