To activate such functionality, enable the serialize extension.
scheduler.plugins({
serialize: true
});
To serialize scheduler data to an XML string, use the toXML method:
var xml = scheduler.toXML(); //xml string
Related sample: Serialize scheduler events
To serialize scheduler data to a JSON string, use the toJSON method:
var json_string = scheduler.toJSON(); //json string
Note, the method returns a JSON string, not object. If you need to get a JSON object - use the getEvents method.
Related sample: Serialize scheduler events
To serialize scheduler data to an ICal string, use the toICal method:
var ical_string = scheduler.toICal(); //ical string
Also, there is an external script for iCal import-export operations
Related sample: Serialize scheduler events
The following technique is not applicable to the iCal format.
By default export will include only standard attributes(properties):
If you need to include some custom attributes, you can redefine the data_attributes method. In the simplest case it will look as in:
scheduler.data_attributes = function(){
return [
["id"],["text"],["date_start"],["date_end"],
["custom_attribute"]
];
};
Basically, the method defines a list of attribute names.
But you can define the formatting function, which describes how attribute data needs to be processed before serialization.
It can be useful for dates that need converting before being placed in XML
scheduler.data_attributes = function(){
return [
["id"],
["text"],
["start_date",scheduler.templates.format_date],
["end_date",scheduler.templates.format_date]];
}
Below technique is not applicable for the iCal format.
If you are using the "recurring" extension, you need to define extra attributes, which are used by recurring events:
scheduler.data_attributes = function(){
var empty = function(a){ return a||""; }
return [["id"],
["text"],
["start_date",scheduler.templates.xml_format],
["end_date",scheduler.templates.xml_format],
["rec_type",empty],
["event_length",empty],
["event_pid",empty]];
}
Serialization allows you to implement a simple routine of data saving, which doesn't require DB - data will be stored in an XML file.
scheduler.plugins({
serialize: true
});
<form id="xml_form" action="xml_writer.php" method="post" target="hidden_frame" >
<input type="hidden" name="data" value="" id="data">
</form>
<input type="button" name="save" value="save" onclick="save()" >
function save(){
var form = document.getElementById("xml_form");
form.elements.data.value = scheduler.toXML();
form.submit();
}
<?php
file_put_contents("./data.xml",$_POST["data"]);
?>
the empty data.xml is:
<data></data>
That's all, now scheduler can be loaded from data.xml, pressing "save" button will serialize the current state of the scheduler to xml and save back to the file.
So, on next loading the scheduler will load events that have been saved previously.
If during data saving, you face unwanted data escaping (in the saved data), make sure that "magic_quotes" is disabled in php configuration.
Back to top