甘特图前身使用JSGrid控件

发布于 2024-12-17 23:08:13 字数 833 浏览 0 评论 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中,什么我必须放吗?如果有人做到了或者知道如何做到这一点,那就太好了。

I am trying to create a Gantt Chart generator, using the Share point control:

<Sharepoint:JsGrid>

I followed this tutorial: How to: Create a Gantt Chart Using the JS Grid Control

I also linked my Sharepoint TaskList as the data Source.

I developped a system of filters using some XML.

But I now want to manage predecessors and represent dependencies by an arrow.

To manage them, I used the last parameter of the EnableGantt function (ganttDependentsColumnName), which one just need the name of the column which contains the dependency information.

What I have to put in this column ?

What I tried is to fill it with the ID of the task, the lane of the DataRow containing predecessors, and I tried to put an object of the class 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);
    }
}

(This code is from the answers in the tutorial)

In the Key, what do I have to put? If someone did it or know how to do it, It could be nice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔少女心 2024-12-24 23:08:13

不确定您是否仍然面临这个问题。但这就是我们为 Predecessors 列所做的,据我所知:

1] 稍微更改 Dependency 类以添加所示的构造函数(否则会出错)。

2]然后,您基本上需要将 Dependency 数组传递给 Predecessors 列,这意味着 JSGrid 控件需要知道起点/行和终点/行依赖关系(因此需要一个数组)。由于继承和 ToJson 方法,JSON 序列化已经得到处理,因此不用担心。

代码:

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;
}

最后,传递调用 EnableGantt() 函数时的 Predecessors 列:

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

确保您的 StartFinishFinishStart 链接类型匹配正确的行,并且您的任务已正确列出,并具有正确的任务开始日期、任务结束日期和前置键。

Not sure if you are still facing this issue. But this is what we did for the Predecessors column and this is as far as I understand this:

1] Change the Dependency class a bit to add a constructor as shown (otherwise it errors out).

2] Then, you basically need to pass a Dependency array to the Predecessors column which means that the JSGrid control needs to know the starting point/row and the ending point/row of the dependency (thus an array is required). JSON Serialization is taken care of already because of the inheritance and the ToJson methods so no worries there.

Code:

1] Dependency Class:

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] Add column if not targeting a SharePoint Task List (where data is an object of DataTable):

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

3] Set the right object array to the Predecessors column:

    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;
}

Finally, pass the Predecessors column while calling the EnableGantt() function:

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

Make sure that your StartFinish and FinishStart link types matches the correct rows and that your tasks are listed correctly with correct task start dates and task end dates and predecessor keys.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文