This is a migrated thread and some comments may be shown as answers.

Duration Column

9 Answers 183 Views
Gantt
This is a migrated thread and some comments may be shown as answers.
Mohammad
Top achievements
Rank 1
Mohammad asked on 30 Dec 2014, 12:42 PM
How to display duration column in radgantt treeview.

9 Answers, 1 is accepted

Sort by
0
Mohammad
Top achievements
Rank 1
answered on 30 Dec 2014, 01:47 PM
Duration text is not appearing in radgantt column.
I have used following code to create Duration column:

<Columns>
<telerik:GanttBoundColumn DataField="Title"></telerik:GanttBoundColumn>
<telerik:GanttBoundColumn DataField="Duration" ></telerik:GanttBoundColumn>
</Columns>



0
Nencho
Telerik team
answered on 02 Jan 2015, 08:36 AM
Hello Mohammad,

Please make sure that the suggestion approach in the following article for the custom fields creation are correctly applied at your end:

http://www.telerik.com/help/aspnet-ajax/gantt-custom-tasks-field.html

Note that you need to define the GanttCustomField in the CustomTaskFields collection as demonstrated in the article above.

Regards,
Nencho
Telerik
0
Felix
Top achievements
Rank 1
answered on 17 Feb 2015, 12:49 PM
Hello,

I tried to add a custom column to show the duration of a task. I already have created a custom column for a description which works. But if I try the same for the custom column duration I get the javascript error:
TypeError: this.duration is not a function
},isMilestone:function(){return this.duration()===0;

So I wonder if this is a bug or my code is buggy.

My code looks like this:

public class CustomGanttTaskFactory : ITaskFactory
    {
        Task ITaskFactory.CreateTask()
        {
            return new CustomTask();
        }
    }

    public class CustomTask : Task
    {
        public string Description
        {
            get { return (string)(ViewState["Description"] ?? ""); }
            set { ViewState["Description"] = value; }
        }

        public double Duration
        {
            get { return (double)(ViewState["Duration"]); }
            set { ViewState["Duration"] = value; }
        }

        protected override IDictionary<string, object> GetSerializationData()
        {
            var dict = base.GetSerializationData();
            dict["Description"] = Description;
            dict["Duration"] = Duration;
            return dict;
        }

        public override void LoadFromDictionary(IDictionary values)
        {
            base.LoadFromDictionary(values);
            Description = (string)values["Description"];
            Duration = (double) values["Duration"];
        }
    }

public class GanttCustomProvider : GanttProviderBase
    {
        public override ITaskFactory TaskFactory
        {
            get { return new CustomGanttTaskFactory(); }
        }

        #region Tasks
        public override List<ITask> GetTasks()
        {
            var tasks = new List<ITask>();
            foreach (var task in GetTasks())
            {
                tasks.Add(new CustomTask
                {
                    ID = task.Id,
                    ParentID = task.ParentID,
                    OrderID = task.OrderID,
                    Start = task.StartDate,
                    End = task.EndDate,
                    Summary = task.IsSummary,
                    Title = task.Name,
                    Description = task.Description,
                    Duration = (task.EndDate - task.StartDate).TotalDays
                });
              
            }
            return tasks;
        }

So I hope you can help me with my duration problem. Thanks.

Regards,
Felix

0
Nencho
Telerik team
answered on 20 Feb 2015, 07:33 AM
Hello Felix,

In the attachment you can find a runnable sample, demonstrating the implementation of the RadGantt with a custom Duration column.

Note : telerik dll files are removed from the attachment.

Regards,
Nencho
Telerik
0
Felix
Top achievements
Rank 1
answered on 20 Feb 2015, 09:02 AM
Hi Nencho,

finally I got it to work. Didn't know that I'm not allowed to set the ClientPropertyName of the CustomField Duration to
"duration" and that I have to give the Datafield of the GanttBoundColumn for the duration the same value as the value of the ClientPropertyName. Thats kind of confusing but now it works. Thank you.

Regards,
Felix
0
Felix
Top achievements
Rank 1
answered on 04 Mar 2015, 08:15 AM
Hi Nencho,

it seems that I was to premature regarding your
runnable example. Because as I tried to implement your solution into my
software I recognized that when I try to insert (same for delete or
update task) a task the page load method is called instead of the insert
method implemented inside the gantt custom provider. After that nothing
more happens except that the browser only shows the loading icon of the
script manager (see attached screenshot). At the moment I'm using the
new Q1 2015 Telerik version. I attach the sp as well and hope you
get the same behavour as I do ;-).



01.<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
02. 
03.<!DOCTYPE html>
04. 
06.<head id="Head1" runat="server">
07.    <title></title>
08.</head>
09.<body>
10.    <form id="form1" runat="server">
11.        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
12.    <div>
13. 
14.        <telerik:RadGantt runat="server" ID="RadGantt1" SelectedView="WeekView"
15.            AutoGenerateColumns="false">
16.            <Columns>
17.                <telerik:GanttBoundColumn DataField="ID" Width="90px"></telerik:GanttBoundColumn>
18.                <telerik:GanttBoundColumn DataField="Title"></telerik:GanttBoundColumn>
19.                <telerik:GanttBoundColumn DataField="Start" HeaderText="Start"></telerik:GanttBoundColumn>
20.                <telerik:GanttBoundColumn DataField="TaskDuration" HeaderText="Duration" UniqueName="TaskDuration"></telerik:GanttBoundColumn>
21.            </Columns>
22.            <CustomTaskFields>
23.                <telerik:GanttCustomField PropertyName="TaskDuration" ClientPropertyName="taskDuration" Type="String" />
24.            </CustomTaskFields>
25.        </telerik:RadGantt>
26. 
27.    </div>
28.    </form>
29.</body>
30.</html>

1.public partial class Default : System.Web.UI.Page
2.{
3.    protected void Page_Load(object sender, EventArgs e)
4.    {
5.        RadGantt1.Provider = new GanttCustomProvider();
6.    }
7.}

001.public class GanttCustomProvider : GanttProviderBase
002.{
003.    public override ITaskFactory TaskFactory
004.    {
005.        get
006.        {
007.            return new CustomGanttTaskFactory();
008.        }
009.    }
010. 
011.    #region Tasks
012. 
013.    public override List<ITask> GetTasks()
014.    {
015.        var tasks = new List<ITask>();
016.        using (var db = new GanttEntities())
017.        {
018.            tasks.AddRange(db.GanttTasks.ToList().Select(task => new CustomTask
019.            {
020.                ID = task.ID,
021.                ParentID = task.ParentID,
022.                OrderID = task.OrderID,
023.                Start = task.Start,
024.                End = task.End,
025.                PercentComplete = task.PercentComplete,
026.                Summary = task.Summary,
027.                Title = task.Title,
028.                Expanded = task.Expanded.HasValue && task.Expanded.Value,
029.                TaskDuration = task.End - task.Start
030.            }));
031.        }
032.        return tasks;
033.    }
034. 
035.    public override ITask UpdateTask(ITask task)
036.    {
037.        using (var db = new GanttEntities())
038.        {
039.            ((CustomTask)task).TaskDuration = task.End - task.Start;
040.            GanttTask entityTask = ToEntityTask(task);
041.            db.GanttTasks.Attach(entityTask);
042.            db.Entry(entityTask).State = EntityState.Modified;
043.            db.SaveChanges();
044.        }
045. 
046.        return task;
047.    }
048. 
049.    public override ITask DeleteTask(ITask task)
050.    {
051.        using (var db = new GanttEntities())
052.        {
053.            GanttTask entityTask = ToEntityTask(task);
054.            db.GanttTasks.Attach(entityTask);
055.            db.GanttTasks.Remove(entityTask);
056.            db.SaveChanges();
057.        }
058.             
059.        return task;
060.    }
061. 
062.    public override ITask InsertTask(ITask task)
063.    {
064.        using (var db = new GanttEntities())
065.        {
066.            task.ID = 0; // Value will be updated from DB
067.            GanttTask entityTask = ToEntityTask(task);
068.            db.GanttTasks.Add(entityTask);
069.            db.SaveChanges();
070. 
071.            task.ID = entityTask.ID;
072.        }
073. 
074.        return task;
075.    }
076. 
077.    #endregion
078. 
079.    #region Dependencies
080. 
081.    public override List<IDependency> GetDependencies()
082.    {
083.        var dependencies = new List<IDependency>();
084.        using (var db = new GanttEntities())
085.        {
086.            dependencies.AddRange(db.GanttDependencies.ToList().Select(dependency => new Dependency()
087.            {
088.                ID = dependency.ID,
089.                PredecessorID = dependency.PredecessorID,
090.                SuccessorID = dependency.SuccessorID,
091.                Type = (DependencyType)dependency.Type
092.            }));
093.        }
094.        return dependencies;
095.    }
096. 
097.    public override IDependency DeleteDependency(IDependency dependency)
098.    {
099.        using (var db = new GanttEntities())
100.        {
101.            GanttDependency entityDependency = ToEntityDependency(dependency);
102.            db.GanttDependencies.Attach(entityDependency);
103.            db.GanttDependencies.Remove(entityDependency);
104.            db.SaveChanges();
105.        }
106.             
107.        return dependency;
108.    }
109. 
110.    public override IDependency InsertDependency(IDependency dependency)
111.    {
112.        using (var db = new GanttEntities())
113.        {
114.            dependency.ID = 0; // Value will be updated from DB
115.            GanttDependency entityDependency = ToEntityDependency(dependency);
116.            db.GanttDependencies.Add(entityDependency);
117.            db.SaveChanges();
118. 
119.            dependency.ID = entityDependency.ID;
120.        }
121.             
122.        return dependency;
123.    }
124. 
125.    #endregion
126. 
127.    #region Helpers
128. 
129.    private GanttTask ToEntityTask(ITask srcTask)
130.    {
131.        return new GanttTask
132.            {
133.                ID = (int)srcTask.ID,
134.                ParentID = (int?)srcTask.ParentID,
135.                OrderID = (int)srcTask.OrderID,
136.                Start = srcTask.Start,
137.                End = srcTask.End,
138.                PercentComplete = srcTask.PercentComplete,
139.                Summary = srcTask.Summary,
140.                Title = srcTask.Title,
141.                Expanded = srcTask.Expanded
142.            };
143.    }
144. 
145.    private GanttDependency ToEntityDependency(IDependency srcDependency)
146.    {
147.        return new GanttDependency
148.        {
149.            ID = (int)srcDependency.ID,
150.            PredecessorID = (int)srcDependency.PredecessorID,
151.            SuccessorID = (int)srcDependency.SuccessorID,
152.            Type = (int)srcDependency.Type
153.        };
154.    }
155. 
156.    #endregion
157.}
158. 
159.public class CustomGanttTaskFactory : ITaskFactory
160.{
161.    Task ITaskFactory.CreateTask()
162.    {
163.        return new CustomTask();
164.    }
165.}
166. 
167.public class CustomTask : Task
168.{
169.    public CustomTask()
170.        : base()
171.    {
172.    }
173. 
174.    public TimeSpan TaskDuration
175.    {
176.        get { return (TimeSpan)(ViewState["TaskDuration"] ?? TimeSpan.MinValue); }
177.        set { ViewState["TaskDuration"] = value; }
178.    }
179. 
180.    protected override IDictionary<string, object> GetSerializationData()
181.    {
182.        var dict = base.GetSerializationData();
183. 
184.        dict["TaskDuration"] = TaskDuration.ToString();
185. 
186.        return dict;
187.    }
188. 
189.    public override void LoadFromDictionary(System.Collections.IDictionary values)
190.    {
191.        base.LoadFromDictionary(values);
192. 
193.        TaskDuration = TimeSpan.Parse(values["TaskDuration"].ToString());
194.    }
195.}

Regards,
Felix
0
Felix
Top achievements
Rank 1
answered on 04 Mar 2015, 10:09 AM
Hi,

additionally to my post before I figuered out that a customganttprovider doesn't work properly if the managed pipeline mode is set to "Integrated". As soon as i set the mode to "Classic" the behaviour is as expected. But if I add an gantt custom field such as description or duration I get an error inside the output view. See below:

[quote]A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.NullReferenceException' occurred in App_Code.mms9agcy.dll
A first chance exception of type 'System.NullReferenceException' occurred in System.Web.Extensions.dll
A first chance exception of type 'System.NullReferenceException' occurred in Telerik.Web.UI.dll
'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/13/ROOT-1-130699372019781403): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Types\11.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Types.dll'. Cannot find or open the PDB file.[/quote]

I hope this helps to find a solution for my problem. Thanks.

Regards,
Felix
0
Nencho
Telerik team
answered on 09 Mar 2015, 02:46 PM
Hello Mohammad,

Regarding the managed pipeline mode - indeed there is such issue, which the developer team already investigates. However, I am afraid that I was unable to replicate the issue that you mentioned. I have used the custom provided implementation that you have demonstrated, but the behavior seems to  be correct at my end.

This is why, I would suggest you to submit a support ticket and attach a runnable sample, demonstrating the problematic behavior at your end. Thus we will be able to inspect it locally and troubleshoot the problem for you.

Regards,
Nencho
Telerik
0
Felix
Top achievements
Rank 1
answered on 09 Mar 2015, 03:03 PM
Hello Nencho,

as I mentioned in my second post the example with the duration works as expected if I set the managed pipeline mode to "Classic".
[quote]additionally to my post before I figuered out that a customganttprovider
doesn't work properly if the managed pipeline mode is set to
"Integrated". As soon as i set the mode to "Classic" the behaviour is as
expected.[/quote]
I have had a problem if I wanted to use e.g. a custom field for a description which I forgot to insert into my example. But in the meantime I figured out what went wrong. Instead of casting my value to a string I wrote "values["Description"].toString()" inside the LoadFromDictionary-method which resulted to my mentioned error. But thanks for your answer.

Regards,
Felix
Tags
Gantt
Asked by
Mohammad
Top achievements
Rank 1
Answers by
Mohammad
Top achievements
Rank 1
Nencho
Telerik team
Felix
Top achievements
Rank 1
Share this question
or