本文中主要包含下面幾個部分:javascript
1.頁面中如何初始化dhtmlxscheduler?css
2.dhtmlxscheduler本地化?html
3.如何實現數據庫的持久化?java
1.頁面中如何初始化dhtmlxscheduler?數據庫
1.1在頁面的開始部分引入相關聯的文件.服務器
<script type="text/javascript" src="<%=basePath%>dhtmlxscheduler/dhtmlxscheduler.js"></script>函數
<link rel="stylesheet" href="<%=basePath%>dhtmlxscheduler/dhtmlxscheduler.css" type="text/css" title="no title" charset="utf-8">post
1.2 在body中添加dhtmlscheduler的渲染位置url
<div id="scheduler_here" class="dhx_cal_container" style='width:100%; height:100%;'> .net
<div class="dhx_cal_navline">
<div class="dhx_cal_prev_button"> </div>
<div class="dhx_cal_next_button"> </div>
<div class="dhx_cal_today_button"></div>
<div class="dhx_cal_date"></div>
<div class="dhx_cal_tab" name="day_tab" style="right:204px;"></div>
<div class="dhx_cal_tab" name="week_tab" style="right:140px;"></div>
<div class="dhx_cal_tab" name="month_tab" style="right:76px;"></div>
</div>
<div class="dhx_cal_header">
</div> <div class="dhx_cal_data">
</div>
< /div>
1.3 添加初始化函數
<script> function init() { scheduler.init('scheduler_here',null,"week"); scheduler.load("events.xml"); } < /script>
1.4在body的onload事件中調用上面的init函數
<body onload="init();">
2.dhtmlxscheduler本地化
dhtmlxscheduler本地化只須要引入兩個js便可文件,能夠修改這兩個js文件,從而實現自定義的本地化。這裏須要注意的是須要使用utf-8的字符集,不然容易產生亂碼。
<!-- 本地化js,這裏須要注意的是這裏須要實現字符集是utf-8 -->
<script src="<%=basePath%>dhtmlxscheduler/sources/locale_cn.js" type="text/javascript" charset="utf-8"></script>
<script src="<%=basePath%>dhtmlxscheduler/sources/locale_recurring_cn.js" type="text/javascript" charset="utf-8"></script>
3.如何實現數據庫的持久化?
3.1如何將數據從數據庫中讀取出來加載到dhtmlxscheduler?
3.2如何和數據庫實現交互?增長,刪除,修改?
3.1如何將數據從數據庫中讀取出來加載到dhtmlxscheduler中?
客戶端:
scheduler.load("url");
服務器端:
首先從數據庫中讀取各個event,而後將各個event格式化成下面的格式,而後輸出:
<data>
<event id="2">
<start_date>2009-05-24 00:00:00</start_date>
<end_date>2009-06-08 00:00:00</end_date>
<text><![CDATA[French Open]]></text>
<details><![CDATA[Philippe-Chatrier Court Paris, FRA]]></details>
</event>
<event id="3">
<start_date>2009-06-10 00:00:00</start_date>
<end_date>2009-06-13 00:00:00</end_date>
<text><![CDATA[Aegon Championship]]></text>
<details><![CDATA[The Queens Club London, ENG]]></details>
</event>
< /data>
3.2如何和數據庫實現交互?增長,刪除,修改?
增長,刪除 ,修改的實現須要經過dhtmlxscheduler事件來實現,實現模板以下(注意須要引入prototype.js文件):
scheduler.attachEvent("onBeforeEventDelete", function(event_id, event_object){
var url = "YOUR-URL";
var id = event_object.id;
var text = event_object.text; // date 須要實現格式化,這裏須要和server端相互交互
var convert = scheduler.date.date_to_str("%Y-%m-%d %H:%i");
var start_date = convert(event_object.start_date);
var end_date = convert(event_object.end_date);
var details = event_object.details;
var pars = "id=" + id + "&start_date=" + start_date + "&end_date=" + end_date + "&text=" + text + "&details=" + details;
// 向數據庫提交
new Ajax.Request(url,{
method:'post',
parameters: pars,
onSuccess: function(transport) {
// 關閉窗口
programing = false;
} });
// 這裏使用true刷心主窗口,將event不顯示
return true; });
scheduler.attachEvent("onEventChanged", function(event_id, event_object){
// 獲得數據
var url = "YOUR-URL";
var id = event_object.id;
var text = event_object.text;
// date 須要實現格式化
var convert = scheduler.date.date_to_str("%Y-%m-%d %H:%i");
var start_date = convert(event_object.start_date);
var end_date = convert(event_object.end_date);
var details = event_object.details;
var pars = "id=" + id + "&start_date=" + start_date + "&end_date=" + end_date + "&text=" + text + "&details=" + details;
// 向數據庫提交
new Ajax.Request(url,{
method:'post',
parameters: pars,
onSuccess: function(transport) {
// 關閉窗口
programing = false;
}
}); });
// 添加事件event scheduler.attachEvent("onEventAdded", function(event_id,event_object){
// 這裏須要引入另外的js庫,將數據提交到後臺保存,好比使用prototype
// 有用鏈接: //
http://blog.csdn.net/bvb09/archive/2009/12/18/5031733.aspx(完整實例)
// http://gh0769.javaeye.com/blog/662511 //
http://www.cnblogs.com/smildlzj/archive/2010/01/07/1641755.html //
http://ynial.javaeye.com/blog/741092
// 向數據庫提交 var url = "YOUR-URL";
var id = event_object.id;
var text = event_object.text;
// date 須要實現格式化 var convert = scheduler.date.date_to_str("%Y-%m-%d %H:%i");
var start_date = convert(event_object.start_date);
var end_date = convert(event_object.end_date);
var details = event_object.details;
var pars = "id=" + id + "&start_date=" + start_date + "&end_date=" + end_date + "&text=" + text + "&details=" + details;
new Ajax.Request(url,{
method:'post',
parameters: pars,
onSuccess: function(transport) {
// 關閉窗口
programing = false;
}
}); });