2014年4月24日 星期四

jQuery.Gantt 設定假日屬性 holidays


參考 : http://taitems.github.io/jQuery.Gantt/

Handler.ashx

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Web.SessionState;
using System.Collections.Generic;

public class Handler : IHttpHandler,IReadOnlySessionState {
    
    public void ProcessRequest (HttpContext context) {
        
        List listHD = new List();
        listHD.Add("[\"/Date(1325433600000)/\"]");
        listHD.Add("[\"/Date(1325520000000)/\"]");
        listHD.Add("[\"/Date(1325692800000)/\"]");
        context.Response.ContentType = "application/json";
        context.Response.Charset = "utf-8";
        context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(listHD));
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

getHD.js

$.ajax({
    type: 'post',
    async: false,
    url: "Handler.ashx",
    dataType: "json",
    contentType: 'application/json; charset=utf-8',
    success: function (result) {
        hd = result;
    },
    error: function () {
        hd = '';
        alert('讀取假日資料錯誤!');
    }
})

gantt.html

<script src="js/getHD.js" type="text/javascript"></script>
$(function() {
  $(".gantt").gantt({
  holidays: hd,
  ...   
}

沒有留言:

張貼留言