0

我正在尝试使用共享点控件创建甘特图生成器:

<Sharepoint:JsGrid>

我遵循了本教程:如何:使用 JS 网格控件创建甘特图

我还将我的 Sharepoint TaskList 链接为数据源。

我使用一些 XML 开发了一个过滤器系统。

但我现在想管理前辈并用箭头表示依赖关系。

为了管理它们,我使用了 EnableGantt 函数 ( ganttDependentsColumnName) 的最后一个参数,它只需要包含依赖信息的列的名称。

我必须在这个专栏里放什么?

我尝试用任务的 ID 填充它,包含前辈的 DataRow 的通道,我尝试放置类 Dependency 的对象:

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

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

(此代码来自教程中的答案)

在 Key 中,我必须放什么?如果有人这样做或知道怎么做,那可能会很好。

4

1 回答 1

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 任务列表(其中数据是 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"
    );

确保您的StartFinishFinishStart链接类型正确的行匹配,并且您的任务已正确列出,其中包含正确的任务开始日期和任务结束日期以及前任键。

于 2012-07-17T05:17:52.877 回答