Data collections

Data collections

Data collections lets you load data statically, without making requests to server and without reloading the page.
You may need data collections in different situations:

In general, to create a data collection and populate some element with it, you should follow these steps:

  1. Create a collection of objects. Objects are instances of any class inherited from System.Object (IEnumerable<object>);
  2. Through method AddOptions(), populate the desired element with the collection. The method takes as a parameter the object created on the previous step.



Here are code samples of data collections you may use in the situations stated above:

Events data collections

You can use data collections to load events to the scheduler.

var items = new List<object>(){
       new { id = "1", text = "first event", start_date = "03.06.2011", end_date = "04.06.2011" },
       new { id = "2", text = "second event", start_date = "05.06.2011", end_date = "06.06.2011" }
};
 
var data = new SchedulerAjaxData(items);

Note, to be correctly processed data items for the controls should have 4 properties:

  • id - (int, string etc.) the event id.
  • start_date - (DateTime or string) the date when an event is scheduled to begin. The default format - ”%m/%d/%Y %H:%i”.
  • end_date - (DateTime or string) the date when an event is scheduled to be completed. The default format - ”%m/%d/%Y %H:%i”.
  • text - (string) the text of an event.

See available variations of the format string here.

Data collection in dropdown lists

You can use a data collection to define select options of a dropdown list, e.g. 'select' control.

var select = new LightboxSelect("textColor", "Priority");
var items = new List<object>(){
                new { key = "gray", label = "Low" },
                new { key = "blue", label = "Medium" },
                new { key = "red", label = "High" }
};
select.AddOptions(items);

Note, to be correctly processed data items for the controls should have 2 properties:

  • key - the id of an option;
  • label - the text label of an option.

Data collections for Timeline view

Y-Axis items in the Timeline view can be specified by data collection.

var timeline = new TimelineView("timeline_id", "room_id");//initializes the view
sched.Views.Add(timeline);//adds the view to the scheduler
 
var rooms = new List<object>(){
                new { key = "1", label = "Room 1"},
                new { key = "2", label = "Room 2"}
};
timeline.AddOptions(rooms);

Note, to be correctly processed data items for the controls should have 2 properties:

  • key - the id of an item;
  • label - the text label of an item.

Data collections for Units view

X-Axis items in the Units view can be specified by data collection.

var unit = new UnitsView("unit1", "room_id");//initializes the view
sched.Views.Add(unit);//adds the view to the scheduler
 
var rooms = new List<object>(){
                new { key = "1", label = "Room 1"},
                new { key = "2", label = "Room 2"}
};
unit.AddOptions(rooms);

Note, to be correctly processed data items for the controls should have 2 properties:

  • key - the id of an item;
  • label - the text label of an item.

comments powered by Disqus