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

How to Populate Gantt

3 Answers 240 Views
Gantt
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 29 Nov 2014, 08:56 AM
Hi,

I'm trying to load the information as a Gantt Chart. Because my data is not structure as the gantt task require, i'created a view with the suggested structure for the Tasks, (i don't know how to populate the dependencies). So my gantt view's structure looks like:
[ID] [int]
[ParentID] [int]
[OrderID] [int]
[Title] [ntext]
[Start] [datetime]
[End] [datetime]
[PercentComplete] [decimal]
[Summary] [bit]

Now, in my ganttPage.aspx 
<telerik:RadGantt runat="server" ID="GanttChart" Skin="Silk" ListWidth="400px" Height="350px" Width="1000px" SelectedView="WeekView" AutoGenerateColumns="false" WorkWeekStart="Monday" WorkWeekEnd="Friday">
    <Columns>
        <telerik:GanttBoundColumn DataField="Title" HeaderText="Attivita" DataType="String" UniqueName="Title" Width="150px" AllowEdit="false"></telerik:GanttBoundColumn>
        <telerik:GanttBoundColumn DataField="Start" HeaderText="Inizio" DataType="DateTime" UniqueName="Start" DataFormatString="dd/MM/yy" Width="65px" AllowEdit="false" />
        <telerik:GanttBoundColumn DataField="End" HeaderText="Fine" DataType="DateTime" UniqueName="End" DataFormatString="dd/MM/yy" Width="65px" AllowEdit="false" />
        <telerik:GanttBoundColumn DataField="PercentComplete" HeaderText="Completamento" DataType="Number" UniqueName="PercentComplete" Width="110px" AllowEdit="false" />
    </Columns>                               
    <DayView UserSelectable="true" SlotWidth="65px" DayHeaderDateFormat="ddd" TimeHeaderDateFormat="H:mm" />
    <WeekView UserSelectable="true" DayHeaderDateFormat="ddd" SlotWidth="65px" WeekHeaderDateFormat="ddd" />
    <YearView UserSelectable="true" MonthHeaderDateFormat="M" YearHeaderDateFormat="Y" SlotWidth="65px" />
    <MonthView UserSelectable="true" SlotWidth="65px" MonthHeaderDateFormat="M" WeekHeaderDateFormat="ddd M/dd" />
     
</telerik:RadGantt>


So i don't wanna use the declarative binding because i need more flexibility, The Xml provider will not solve my problem. And the data source... i can't make it work :S...  Would be great!

I also want to show multiple projects in my gantt chart, it's that possible?


help me please...

Thanks!!!

3 Answers, 1 is accepted

Sort by
0
Accepted
Bozhidar
Telerik team
answered on 01 Dec 2014, 07:20 AM
Hi,

DataBinding through the DataSource property in Code Behind was introduced in the official release of the control, in Q3 2014, so if you are using the older version you won't be able to use it. And if you want to create a more specific binding scenario, you can create a custom provider, as explained in the following help article:
http://www.telerik.com/help/aspnet-ajax/gantt-providers-customentityprovider.html

Regards,
Bozhidar
Telerik
0
Richard
Top achievements
Rank 1
answered on 01 Dec 2014, 01:50 PM
Hi, thanks for the answer!

i've been trying many things to make it work. i have found some problems. 
The first one:
I  Can't use a list of ITask with .Net Framework 3.5, for some reason the code 

 public override List<ITask> GetTasks()
        {
            var tasks = new List<ITask>();

            using (var db = new GanttEntities())
            {
                tasks.AddRange(db.GanttTasks.ToList().Select(task => new Task
                {
                    ID = task.ID,
                    ParentID = task.ParentID,
                    OrderID = task.OrderID,
                    Start = task.Start,
                    End = task.End,
                    PercentComplete = task.PercentComplete,
                    Summary = task.Summary,
                    Title = task.Title,
                    Expanded = task.Expanded.HasValue && task.Expanded.Value
                }));
            }

            return tasks;

 the way it works for me is

public class myTask
    {
        public int Id { get; set; }
        public int ParentId { get; set; }
        public int OrderId { get; set; }
        public DateTime Start { get; set; }
        public DateTime End { get; set; }
        public decimal PercentComplete { get; set; }
        public bool Summary { get; set; }
        public string Title { get; set; }
        public bool Expanded { get; set; }
    }
and
 public override List<ITask> GetTasks()
        {

            List<ITask> tasks = new List<ITask>();

            using (var db = new GanttEntities())
            {
               var query = (from t in db.GanttTasks select new myTask
                             {
                                 Id = f.Id,
                                 ParentId = t.ParentId == null ? 0 : (int)t.ParentId,
                                 OrderId = t.ProjectId,
                                 Start = (DateTime)t.Start,
                                 End = (DateTime)t.End,
                                 PercentComplete = t.PercentComplete == null ? 0 : (decimal)t.PercentComplete,
                                 Summary = t.Summary == 1 ? true : false,
                                 Title = t.Title,
                                 Expanded = true
                             }).ToList();

Then iterate and add it to the list of task as a Task item.  Another problem is the casting of an Int to an Object from the IDs (ID, ProjectID, OrderID).

The Second problems is that the GanttChart, is not showing anything.  in my page's code behind i'm using:

GanttChart.Provider = new GanttProvider();

as the suggested example. 

There's anything wrong in my code?

Thanks again!!!
 
0
Bozhidar
Telerik team
answered on 03 Dec 2014, 09:51 AM
Hi,

I've attached a runnable sample page demonstrating databinding through the DataSource property of the Gantt control in code behind. Please run it on your end and see if any issues arise.

Regards,
Bozhidar
Telerik
Tags
Gantt
Asked by
Richard
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Richard
Top achievements
Rank 1
Share this question
or