You can create a custom view for scheduler. All the needed information is given in the current article.
The following instructions explain how to add a custom view to your calendar created with Scheduler .NET.
There are two main steps to create a custom view:
In order to add a new view to the client side scheduler, you need to define at least three mandatory methods that should do the following:
Defining these methods will allow you to have a custom 'weekly' based mode, for example 'two week view', or 'decade view' (i.e. time scale is at the left side and day-columns are placed from left to right).
Methods specs:
Returns: Date
Returns: Date
Returns: Date
Where {viewName} is an arbitrary name of the custom view. For example: scheduler.date.twoWeek_start, scheduler.get_twoWeek_end, scheduler.date.add_twoWeek.
For more details follow these instructions.
In order to get a fully custom display, as it's made for Grid, Agenda and Timeline views, you need to define the following functions in addition to the mandatory ones:
scheduler.templates.{viewName}_date = function(start_date, end_date){
...
}
scheduler.templates.{viewName}_date = function(start_date, end_date){
...
}
It is recommended to write the code for a custom view in the handler of the OnTemplateReady event for correct rendering on a page. That event fires when the scheduler templates are ready.
You can find more information on this issue here.
You can add your own views in Scheduler .NET by creating a new class view derived from the base class SchedulerView.
The SchedulerView class has the following members:
<script type="text/javascript">
scheduler.attachEvent("onTemplatesReady", function () {
//work week
scheduler.date.workweek_start = scheduler.date.week_start;
scheduler.templates.workweek_date = scheduler.templates.week_date;
scheduler.templates.workweek_scale_date = scheduler.templates.week_scale_date;
scheduler.date.add_workweek = function (date, inc) { return scheduler.date.add(date, inc * 7, "day"); }
scheduler.date.get_workweek_end = function (date) { return scheduler.date.add(date, 5, "day"); }
});
</script>
Let's create a work week view class. The logic of this view was defined earlier via JavaScript. Now we add this view to the Scheduler.NET:
public class WorkWeekView : SchedulerView
{
public WorkWeekView(): base()
{
// view type must be equal to the one defined on the client
Name = ViewType = "workweek";
}
}
Then add your view to the scheduler:
var calendar = new DHXScheduler();
...
calendar.Views.Add(new WorkWeekView()
{
Label = "W-Week"
});
...
<script type="text/javascript">
function beforeInit() {
scheduler.attachEvent("onTemplatesReady", function () {
//work week
scheduler.date.workweek_start = scheduler.date.week_start;
scheduler.templates.workweek_date = scheduler.templates.week_date;
scheduler.templates.workweek_scale_date = scheduler.templates.week_scale_date;
scheduler.date.add_workweek = function (date, inc) { return scheduler.date.add(date, inc * 7, "day"); }
scheduler.date.get_workweek_end = function (date) { return scheduler.date.add(date, 5, "day"); }
//decade
scheduler.date.decade_start = function (date) {
var ndate = new Date(date.valueOf());
ndate.setDate(Math.floor(date.getDate() / 10) * 10 + 1);
return this.date_part(ndate);
}
scheduler.templates.decade_date = scheduler.templates.week_date;
scheduler.templates.decade_scale_date = scheduler.templates.week_scale_date;
scheduler.date.add_decade = function (date, inc) { return scheduler.date.add(date, inc * 10, "day"); }
});
}
</script>
Create a decade view class. The logic of the decade view will be added later:
public class DecadeView : SchedulerView
{
public DecadeView()
: base()
{
// view type must be equal to the one defined on the client
Name = ViewType = "decade";
}
}
Now we simply add this view to the Scheduler .NET:
var scheduler = new DHXScheduler();
...
scheduler.Views.Add(new DecadeView()
{
Label = "Decade"
});
...
Creating a fully custom view requires working with the internal API and private methods of the scheduler, which is usually not recommended and doesn't guarantee backward compatibility.
scheduler.{viewname}_view(boolean activated)
will be called each time the view is activated or deactivated. You can render the view's markup and inject it into the calendar container there. When the view is deactivated you can clear any temporary values.
A sample for scheduler.agenda_view:
scheduler.agenda_view=function(mode){
scheduler._min_date = scheduler.config.agenda_start||scheduler.date.agenda_start(scheduler._date);
scheduler._max_date = scheduler.config.agenda_end||scheduler.date.add_agenda(scheduler._min_date, 1);
scheduler._table_view = true;
set_full_view(mode);
if (mode){
// agenda tab activated
} else {
// agenda tab de-activated
}
};
You can find the full code on GitHub.
You'll also need to create a wrapper around the scheduler.render_data method for rendering events in a custom view. The method should generate HTML or DOM elements for the events and append them to the data layout.
scheduler.render_data(Array events)
scheduler.render_data=function(evs){
if (this._mode == "agenda")
//fill agenda tab
else
return old.apply(this,arguments);
};
You can find the full code on GitHub.
scheduler.render_data = function(evs) {
if (!is_year_mode()) return old.apply(this, arguments);
for (var i = 0; i < evs.length; i++)
this._year_render_event(evs[i]);
};
You can find the full code on GitHub.
When you'll be rendering events in a custom view, make sure that the event elements have the "event_id" attribute set. It will allow scheduler to trace clicks and double clicks on events. You can see an example on GitHub.
That's it for a basic agenda or grid-like view. Although, drag-and-drop support would require some additional coding.