不知道你是否仍然面臨這個問題。但這是我們爲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"
);
確保您StartFinish和FinishStart鏈接類型匹配正確的行和你的任務是用正確的正確列任務開始日期和任務結束日期以及前任密鑰。