Any thoughts on how to fix this problem? I have a timelineview in tree mode that works well when we’re just trying to pass key and label properties. However, we’d like to pass more properties to the client side so we can use that for calculating whether we should display a different image for a row label. When the object is added to the timelineview using AddOptions(), the object has all the properties we need, but on the client side, only key and label are available. I looked at the car rental mvc5 and used the javascript code from there to create a label for each row.
Snippet from controller:
protected TimelineView GenericTimeline(string name, IEnumerable categoryAreas)
{
var timeline = new TimelineView(name, “area_id”);
timeline.FolderEventsAvailable = false;
timeline.RenderMode = TimelineView.RenderModes.Tree;
foreach (var catArea in categoryAreas)
{
//TODO: look at adding more properties of object because in the javascript code we are testing for missing object properties
var section = new TimelineUnit(string.Format("category-{0}", catArea.Category.CatId), catArea.Category.Name, false);
// Add the parent folder
timeline.AddOption(section);
// Add the children
//section.AddOptions(catArea.Areas.Select(a => new TimelineUnit(a.area_id, a.label)));
section.AddOptions(catArea.Areas);
}
return timeline;
}
Models:
public class Category
{
public int CatId { get; set; }
public string Name { get; set; }
// Custom property for dhtmlx scheduler
public bool open { get; set; }
public bool parent { get; set; }
public object key { get; set; }
public object label { get; set; }
}
public class Area
{
public object key { get; set; }
public object label { get; set; }
public int area_id { get; set; }
public bool Status { get; set; }
}
public class CategoryAreas
{
public Category Category { get; set; }
public IEnumerable Areas { get; set; }
}
Snippet from javascript:
function defineTemplates() {
…
var label_template = function (key, label, obj) {
// Check for category or area
if (obj.parent != true)
// Area
return obj.label + obj.Status;
else
// Category
return obj.label;
};
for (var i in scheduler.matrix) {
scheduler.templates[i + ‘_scale_label’] = label_template;
}
}