2011-11-22 41 views
0

我想創建一個甘特圖生成器,使用共享點控制甘特圖前輩:使用JSGrid控制

<Sharepoint:JsGrid> 

我跟着這個教程:How to: Create a Gantt Chart Using the JS Grid Control

我也與我的SharePoint任務列表作爲數據源。

我使用一些XML開發了一個過濾器系統。

但我現在想要管理前輩並用箭頭表示依賴關係。

爲了管理它們,我使用了EnableGantt函數的最後一個參數(ganttDependentsColumnName),它只需要包含依賴信息的列的名稱。

我必須把這個專欄放在什麼位置?

我想什麼是任務,包含前輩的DataRow車道的ID,以填補它,我試圖把類依賴的對象:

class Dependency : IJsonSerializable 
{ 
    public object Key {get; set;} // RecordKey 
    public LinkType{get; set;} //LinkType 

    public string ToJson(Serializer s) 
    { 
     return JsonUtility.SerializeToJsonFromProperties(s,this); 
    } 
} 

(此代碼是從教程中的答案)

在密鑰中,我必須放什麼?如果有人做了它或知道如何做,它可能會很好。

回答

1

不知道你是否仍然面臨這個問題。但這是我們爲Predecessors列所做的,這是據我所知:

1]更改Dependency類有點添加一個構造函數(如圖所示)(否則它會出錯)。

2]然後,您基本上需要將Dependency數組傳遞到Predecessors列,這意味着JSGrid控件需要知道依賴項的起始點/行和結束點/行(因此需要數組) 。 JSON序列化已經由於繼承和ToJson方法,所以不用擔心。

代碼:

1]相關性類:

public class Dependency : IJsonSerializable 
{ 
    public object Key { get; set; } // recordKey 
    public LinkType Type { get; set; } // SP.JsGrid.LinkType 

    public Dependency() { 
     Key = DBNull.Value; 
     Type = LinkType.FinishStart; 
    } 

    public string ToJson(Serializer s) 
    { 
     return JsonUtility.SerializeToJsonFromProperties(s, this); 
    } 
} 

2]添加柱如果不針對一個SharePoint任務列表(其中,數據是數據表的一個對象):

data.Columns.Add(new DataColumn("Predecessors",typeof(Dependency[]))); 

3]將正確的對象數組設置爲Predecessors列:

if (<<A predecessor exists>>){ 
    Dependency[] dep = new Dependency[2]; 
    dep[0] = new Dependency(); 
    try{ 
     /* 
     // Unique Identifier for your row based on what you are 
     // passing to the GridSerializer while initializing it 
     // (as a third parameter which is called keyColumnName) 
     // In my case I had to get it by doing some coding as 
     // shown. The first object in the array represents the 
     // previous row and so the unique identifier should 
     // point to the previous row 
     */ 
     dep[0].Key = (
       data.Select(
        "ID=" + 
        data.Rows[s]["PredecessorsID"].ToString() 
        ) 
        [0]["Key"] 
       ); 
    }catch (Exception ex){ 
     dep[0].Key = DBNull.Value; 
    } 
    dep[0].Type = LinkType.FinishStart; 

    /* 
    // Unique Identifier for your row based on what you are 
    // passing to the GridSerializer while initializing it 
    // (as a third parameter which is called keyColumnName) 
    // In my case I had to get it by doing some coding as 
    // shown. The second object in the array represents the 
    // current row and so the unique identifier should 
    // point to the current row 
    */ 
    dep[1] = new Dependency(); 
    try{ 
     dep[1].Key = data.Rows[s]["Key"]; 
    }catch (Exception ex){ 
     dep[0].Key = DBNull.Value; 
    } 
    dep[1].Type = LinkType.StartFinish; 
    data.Rows[s]["Predecessors"] = dep; 
} 

最後,通過Predecessors列,同時調用EnableGantt()功能:

gds.EnableGantt(
    Convert.ToDateTime(
     dr["start Date"] 
    ), 
    Convert.ToDateTime(
     dr["Due Date"] 
    ), 
    GanttUtilities.GetStyleInfo(), 
    "Predecessors" 
    ); 

確保您StartFinishFinishStart鏈接類型匹配正確的行和你的任務是用正確的正確列任務開始日期和任務結束日期以及前任密鑰。