[SP-2010] Predecessor in Gantt Chart using JSGrid

Hi everyone,

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

<Sharepoint:JsGrid>

I followed tutorial :

http://msdn.microsoft.com/en-us/library/ff407962.aspx

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. 

 

Thanks for your answers

November 22nd, 2011 9:15am

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 (now at least the arrows are showing up !!! Phew !!!):

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 match the correct rows and your tasks are listed correctly with correct task start dates and task end dates and predecessor keys.


Free Windows Admin Tool Kit Click here and download it now
July 17th, 2012 5:08am

Hi

I know this is old, but thank you for this, got the precedessors working in about 5 min. 

Just some mods to the above in the one below (see bold) that was 0 needs to be 1 

dep[1] = new Dependency(); try { dep[1].Key = data.Rows[s]["Key"]; } catch (Exception ex) { dep[1].Key = DBNull.Value; } dep[1].Type = LinkType.StartFinish;

and if you are using the Microsoft Example for JSGrid then in GridUtilities.cs in the formatGridField ensure that you add this             if (dc.ColumnName != "Key" && dc.ColumnName != "Predecessors"


July 28th, 2015 11:36pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics