How To Show Multiple Projects RadGanttChart?

5 posts, 1 answers
  1. Richard
    Richard avatar
    9 posts
    Member since:
    Nov 2010

    Posted 03 Dec 2014 Link to this post


    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" >
          <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" />
         <YearView UserSelectable="true" />
          <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" />
    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;
                            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));
                    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");
                return xdoc;
    // Binding
    GanttChart.DataSource = model.GetGanttDataSource(selectedProjectId);

    Any Idea?

  2. Answer
    Bozhidar avatar
    1189 posts

    Posted 03 Dec 2014 Link to this post


    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.

  3. Guss
    Guss avatar
    28 posts
    Member since:
    Nov 2011

    Posted 22 Sep 2016 Link to this post

    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
      <asp:Parameter Name="ProjectId" Type="Int32" DefaultValue="1"/>
    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)
      <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"/>
    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)

  4. Guss
    Guss avatar
    28 posts
    Member since:
    Nov 2011

    Posted 22 Sep 2016 in reply to Guss Link to this post

    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:

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

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

  5. Guss
    Guss avatar
    28 posts
    Member since:
    Nov 2011

    Posted 22 Sep 2016 Link to this post

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

    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.

Back to Top