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

How To Show Multiple Projects RadGanttChart?

4 Answers 147 Views
Gantt
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 03 Dec 2014, 08:40 AM
Hi,

I'm trying to show more than one projects on a single GanttChart. I've tried using an xmlProvider an using the structure <Projects><Project><Tasks><Task>, but nothing happens. The xmlProvider throw me an exception "incorrect structure". There's any way to do that?

my code:
<telerik:RadGantt runat="server" ID="GanttChart" CssClass="GanttChart"  OnDataBound="GanttChart_DataBound" Skin="Silk" ListWidth="400px" Height="450px" 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>
     <YearView UserSelectable="true" />
     <DataBindings>
      <TasksDataBindings IdField="ID" ParentIdField="ParentID" StartField="Start" SummaryField="Summary"    EndField="End" TitleField="Title" PercentCompleteField="PercentComplete" OrderIdField="OrderID" />
<DependenciesDataBindings TypeField="Type" IdField="ID" PredecessorIdField="PredecessorID"  SuccessorIdField="SuccessorID" />
  </DataBindings>
  </telerik:RadGantt>
My code behind
public XElement GetGantTasksByProjectId(int projectId)
        {
            using (var db = new HrNoteEntities())
            {
                var tasks = (from t in db.vw_sw_GanttTasks
                             where t.ProjectId == projectId
                             orderby t.ParentId, t.Start
                             select new
                             {
                                 ID = t.ID,
                                 ParentId = t.ParentId,
                                 Start = t.Start,
                                 End = t.End,
                                 PercentComplete = t.PercentComplete == null ? 0 : t.PercentComplete,
                                 Summary = t.Summary == 1 ? true : false,
                                 ProjectId = t.ProjectId,
                                 Title = t.Title
                             });
 
                XElement tasksList = new XElement("Tasks");
 
                int hasNext = 0;
 
                foreach (var item in tasks)
                {
                    XElement task;
 
                    if (item.ParentId > 0)
                        hasNext = 0;
                    else
                        hasNext = 1;
 
 
                    task = new XElement("Task",
                        new XElement("ID", item.ID),
                        new XElement("ParentID", item.ParentId),
                        new XElement("Start", item.Start.ToString()),
                        new XElement("End", item.End.ToString()),
                        new XElement("Title", item.Title),
                        new XElement("PercentComplete", ((decimal)item.PercentComplete).ToString("G")),
                        new XElement("Summary", item.Summary),
                        new XElement("Expanded", true),
                        new XElement("OrderID", item.ProjectId)
                        );
 
                    if (hasNext == 1 && tasksList.HasElements)
                        tasksList.Add(new XElement("NextID", item.ID));
 
                    tasksList.Add(task);
                }
                return tasksList;
            }
        }
 
        public XDocument GetGanttByProjectId(int projectId)
        {
 
            XDocument xdoc = new XDocument();
            XElement project = new XElement("Project");
            xdoc.Declaration = new XDeclaration("1.0", "utf-16", "true");
 
            project.Add(GetGantTasksByProjectId(projectId));
            xdoc.Add(project);
 
            return xdoc;
 
        }
 
 
// Binding
 
GanttChart.DataSource = model.GetGanttDataSource(selectedProjectId);
 
GanttChart.DataBind();


Any Idea?

Thanks,

4 Answers, 1 is accepted

Sort by
0
Accepted
Bozhidar
Telerik team
answered on 03 Dec 2014, 09:03 AM
Hi,

The Gantt control doesn't support loading of multiple projects. You will have to implement the logic for choosing the project outside of the Gantt control, and use it to show only the current one.

Regards,
Bozhidar
Telerik
0
Guss
Top achievements
Rank 2
Veteran
answered on 22 Sep 2016, 11:36 AM

It can easily support multiple project. Here is what I did using the declarative SQL data source:

  1. Add [ProjectId] INT to your GanttTasks table
  2. Change your SELECT statement to 
    SELECT [ID], [ParentID], [OrderID], [Title], [Start], [End], [PercentComplete], [Expanded], [Summary] FROM [dbo].[GanttTasks] WHERE [ProjectId] = @ProjectId
  3. DO NOT do this:  (it will not know what to do with this new field called 'ProjectId'
    SELECT * FROM [dbo].[GanttTasks] WHERE [ProjectId] = @ProjectId
  4. Obviously add the select parameter
    <SelectParameters>
    <asp:Parameter Name="ProjectId" Type="Int32" DefaultValue="1"/>
    </SelectParameters>
  5. Where I have used DefaultValue="1", you should change to anything you like. Either the SelectedValue from a project combobox, querystring, session, etc. - Standard ASP.NET stuff.
  6. Then you will have to handle the insert command aswell. Like this:
    INSERT INTO [GanttTasks] ([ProjectId], [ParentID], [OrderID], [Title], [Start], [End], [PercentComplete], [Expanded], [Summary]) VALUES (@ProjectId, @ParentID, @OrderID, @Title, @Start, @End, @PercentComplete, @Expanded, @Summary)
  7. From the above, you will see that I pushed in the ProjectId (it is set to NOT ALLOW NULLS in my table)
    <InsertParameters>
    <asp:Parameter Name="ProjectId" Type="Int32" DefaultValue="1"/>
    <asp:Parameter Name="ParentID" Type="Int32"/>
    <asp:Parameter Name="OrderID" Type="Int32" />
    <asp:Parameter Name="Title" Type="String"/>
    <asp:Parameter Name="Start" Type="DateTime"/>
    <asp:Parameter Name="End" Type="DateTime"/>
    <asp:Parameter Name="PercentComplete" Type="Decimal"/>
    <asp:Parameter Name="Expanded" Type="Boolean"/>
    <asp:Parameter Name="Summary" Type="Boolean"/>
    </InsertParameters>
  8. Again, where I have DefaultValue="1", you will have your SessionId, or selectedvalue, or querystring paramater.
  9. Your Update stays stock standard (because when you update a record, you obviously do not care about project id, because the task is already in the correct project!)
  10. You delete statement also stays stock standard.

Capish :-) (Multiple project out of the box !, no code behind)

0
Guss
Top achievements
Rank 2
Veteran
answered on 22 Sep 2016, 12:25 PM

And in addition, also the dependencies selector:

SELECT * FROM [GanttDependencies] WHERE PredecessorID IN (SELECT x.ID FROM dbo.GanttTasks x WHERE x.ProjectId = @ProjectId) OR SuccessorID IN (SELECT y.ID FROM dbo.GanttTasks y WHERE y.ProjectId = @ProjectId)

and the select parameter of:

<SelectParameters>
<asp:Parameter Name="ProjectId" Type="Int32" DefaultValue="1"/>
</SelectParameters>

Do not forget to optimize and set your indices so that your queries do not kill the poor database server.

0
Guss
Top achievements
Rank 2
Veteran
answered on 22 Sep 2016, 02:29 PM

Here is another nice thing to do (I hate useless headers if a symbol can show you everything)

<style type="text/css">
.RadGantt_Bootstrap .rgtTreelist .rgtTreelistGroup {font-weight:bolder !important;}
th[data-field="percentComplete"] {font-family:FontAwesome;}
</style>

And then in your column definition:

<telerik:GanttBoundColumn DataField="PercentComplete" HeaderText="" DataFormatString="P0"></telerik:GanttBoundColumn>

That's symbol is [& # x f 11 e ;] (without the spaces, its the cheat for a FontAwesome checkered flag)
See attached image.

Tags
Gantt
Asked by
Richard
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Guss
Top achievements
Rank 2
Veteran
Share this question
or