不确定您是否仍然面临这个问题。但这就是我们为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 任务列表(其中数据是 DataTable 的对象),则添加列:
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链接类型与正确的行匹配,并且您的任务已正确列出,其中包含正确的任务开始日期和任务结束日期以及前任键。