Gantt Chart Not Displaying Data when SubTasks Attached

Dear Syncfusion Team,

I would like to take this opportunity to express my sincere gratitude for the exceptional work you’ve done in creating such a comprehensive suite of controls. Your commitment to providing a community license is greatly appreciated, as it allows developers like myself to create and innovate without financial constraints. Your efforts have not gone unnoticed and are truly making a difference in the developer community.

-------------------------------------------------------------------------------------------------------------------------------------------------------------

I have created Blazor Web App (24.2.3) with configurations

Version: .Net8

Theme: Bootstrap v5

Authentication: Individual Accounts

Interactivity type: Server

Interactivity location: Per page/component

This is my Dtos 

public class ProjectMetallicConstructionGanttDto

{

    public int TaskId { get; set; }

    public string TaskName { get; set; } = string.Empty;

    public DateTime StartDate { get; set; }

    public DateTime EndDate { get; set; }

    public string Duration { get; set; } = string.Empty;

    public int Progress { get; set; }

    public string Predecessor { get; set; } = string.Empty;

    public int? ParentId { get; set; }

    public List<ProjectMetallicConstructionGanttDetailsDto>? SubTasks { get; set; }

}

public class ProjectMetallicConstructionGanttDetailsDto

{

    public int TaskId { get; set; }

    public string TaskName { get; set; } = string.Empty;

    public DateTime StartDate { get; set; }

    public DateTime EndDate { get; set; }

    public string Duration { get; set; } = string.Empty;

    public int Progress { get; set; }

    public string Predecessor { get; set; } = string.Empty;

    public int? ParentId { get; set; }

}

And This is my endpoints

public static void MapProjectMetallicConstructionEndpoints(this IEndpointRouteBuilder builder)
{
    builder.MapGet("projectchinfo", async (SqlConnectionFactory sqlConnectionFactory) =>
    {
        using var connection = sqlConnectionFactory.Create();
        try
        {
            var lookup = new Dictionary<int, ProjectMetallicConstructionGanttDto>();

            var result = await connection.QueryAsync<ProjectMetallicConstructionGanttDto, ProjectMetallicConstructionGanttDetailsDto, ProjectMetallicConstructionGanttDto>(
                "ProjectMetallicConstructionGanttDto",
                (gantt, details) =>
                {

                    if (!lookup.TryGetValue(gantt.TaskId, out ProjectMetallicConstructionGanttDto ganttEntry))
                    {
                        lookup.Add(gantt.TaskId, ganttEntry = gantt);
                    }

                    ganttEntry.SubTasks ??= [];

                    if (details != null)
                        ganttEntry.SubTasks.Add(details);

                    return ganttEntry;
                },
                splitOn: "TaskId",
                commandType: CommandType.StoredProcedure
            );

            var projectList = lookup.Values.ToList();
            return projectList.Any() ? Results.Ok(projectList) : Results.NotFound("No data found.");
        }
        catch (Exception ex)
        {
            // Log the exception here
            return Results.Problem($"An error occurred while fetching data. {ex.Message}");
        }
    });
}

This is the result from endpoints

[
  {
    "taskId": 1,
    "taskName": "Main task",
    "startDate": "2023-11-15T00:00:00",
    "endDate": "2024-02-06T00:00:00",
    "duration": "60",
    "progress": 0,
    "predecessor": "",
    "parentId": null,
    "subTasks": [
      {
        "taskId": 2,
        "taskName": "Sub task",
        "startDate": "2023-11-16T00:00:00",
        "endDate": "2023-11-27T00:00:00",
        "duration": "11",
        "progress": 0,
        "predecessor": "",
        "parentId": 1
      }
    ]
  }
]

And this is my stored procudre

ALTER PROCEDURE ProjectMetallicConstructionGanttDto
AS
BEGIN
    ;WITH ProjectTasks AS (
        -- Main tasks query
        SELECT
            ROW_NUMBER() OVER (ORDER BY i.DateProject) AS TaskId,
            CONCAT(i.ProjectN,' ',c.Name,' ',FORMAT(i.Weight, 'N2'),' Kg',' -',
            CASE
                WHEN FKPaint=2 THEN 'Peinture'
                WHEN FKGalva=3 THEN 'Galvanisation'
                WHEN FKNoir=4 THEN 'Noir'
                ELSE '' END) AS TaskName,
            i.DateProject AS StartDate,
            i.DateDelivery AS EndDate,
            CAST(i.DeadLineProject AS NVARCHAR(50)) AS Duration,
            0 AS Progress, -- You need to determine how to calculate progress
            '' AS Predecessor -- You need to determine the predecessor logic
        FROM ProjectInfo i
        INNER JOIN Customer c ON i.FK_Customer = c.ID
        WHERE  i.DateDelivery >= '01-02-2024' AND i.id=2287
    ),
    SubTasks AS (
        -- Subtasks query
        SELECT
            p.PlanningCategoryId AS TaskId,
            pc.Title AS TaskName,
            p.StartDate,
            p.EndDate,
            CAST(p.Duration AS NVARCHAR(50)) AS Duration,
            CAST(p.Progress AS NVARCHAR(50)) AS Progress,
            --p.Progress,
            --p.Predecessor,
            ROW_NUMBER() OVER (ORDER BY i.DateProject) AS ParentId
        FROM MetallicConstructionPlanning p
        INNER JOIN PlanningCategory pc ON p.PlanningCategoryId = pc.Id
        INNER JOIN ProjectInfo i ON p.MetallicConstructionId = i.id
    )
    -- Combine the main tasks with subtasks
    SELECT
        pt.*,
        st.TaskId,
        st.TaskName,
        st.StartDate,
        st.EndDate,
        st.Duration,
        st.Progress,
        st.ParentId
        --st.Predecessor
    FROM ProjectTasks pt
    LEFT JOIN SubTasks st ON pt.TaskId = st.ParentId
    ORDER BY pt.TaskId, st.TaskId
END

And this is my code from razor page

@if (projectInfos != null)
{
    <div id="ControlRegion" >
        <SfGantt DataSource="@projectInfos" WorkWeek="@(new string[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday" })" HighlightWeekends="true" RowHeight=25 Height="600px" Width="900px" AllowFiltering="true" EnableContextMenu="true" GridLines="Syncfusion.Blazor.Gantt.GridLine.Both"
                 Toolbar="@(new List<string>() { "CollapseAll","ExpandAll", "Search", "ZoomIn","ZoomOut","ZoomToFit"  })">
            <GanttTaskFields Id="TaskId" Name="TaskName" StartDate="StartDate" EndDate="EndDate"
                             Duration="Duration" Progress="Progress" Dependency="Predecessor" Child="SubTasks">
            </GanttTaskFields>
            <GanttLabelSettings TValue="ProjectMetallicConstructionGanttDto">
                <RightLabelTemplate>
                    <div class="e-right-label-inner-div" style="height:19px;margin-top:3px;">
                        <span class="e-label">@((context as ProjectMetallicConstructionGanttDto).TaskName.Substring(0,9))</span>
                    </div>
                </RightLabelTemplate>
            </GanttLabelSettings>

            <GanttEditSettings AllowEditing="true" AllowTaskbarEditing="true" AllowAdding="true" AllowDeleting="true" ShowDeleteConfirmDialog="true"></GanttEditSettings>
            <GanttSearchSettings Fields="@Searchfields"></GanttSearchSettings>

            <GanttTimelineSettings TimelineUnitSize="@DefaultUnitWidth">
                <GanttTopTierSettings Unit="@TopTierUnit" Count="@TopTierCount" Format="@TopTierFormat"></GanttTopTierSettings>
                <GanttBottomTierSettings Count="@BottomTierCount" Unit="@BottomTierUnit" Format="@BottomTierFormat"></GanttBottomTierSettings>
            </GanttTimelineSettings>
        </SfGantt>
    </div>
    <br />
}
<br/>

@code{
    public DateTime ProjectStart = new DateTime(2023, 1, 11);
    public DateTime ProjectEnd = new DateTime(2024, 2, 6);
    public int DefaultUnitWidth = 33;
    public int TopTierCount = 1;
    public int BottomTierCount = 1;
    TimelineViewMode TopTierUnit = TimelineViewMode.Week;
    TimelineViewMode BottomTierUnit = TimelineViewMode.Day;
    string TopTierFormat = "MMM dd, yyyy";
    string BottomTierFormat = "";
    public string[] Searchfields = new string[] { "TaskId", "TaskName", "StartDate", "EndDate", "Duration", "Progress", "Predecessor" };

    private List<ProjectMetallicConstructionGanttDto>? projectInfos { get; set; }
    protected override async Task OnInitializedAsync()
    {
        projectInfos = await ProjectInfoService.GetProjectInfosAsync();
    }
   
}


Now when there is no SubTasks the gantt show all data but when there is  SubTasks the  gantt show No records to display message .
can you plesae help me to solve this issue

Thank you once again for your outstanding contribution.


7 Replies

AG Ajithkumar Gopalakrishnan Syncfusion Team February 15, 2024 02:10 PM UTC

Hi Mahfoud,

Greetings from Syncfusion Support,

We will check for feasibility to meet your requirement  and we will provide you further details by or before Feb, 19, 2024.

Regards,

Ajithkumar G



AG Ajithkumar Gopalakrishnan Syncfusion Team February 19, 2024 02:18 AM UTC

Hi Mahfoud,

We suggest using a self-referencing data structure of the data source for easier database connectivity in Gantt Chart . Refer to the documentation link:-

Documentation : https://blazor.syncfusion.com/documentation/gantt-chart/data-binding#hierarchical-data-binding

In addition to that, we have shared the dataStructure of Hierarchy collection

Video reference: https://www.syncfusion.com/downloads/support/directtrac/general/ze/GanttSelf-1755646381.zip

Document link: https://blazor.syncfusion.com/documentation/common/data-binding/bind-entity-framework

Data binding : https://blazor.syncfusion.com/documentation/gantt-chart/data-binding#self-referential--flat-data-binding

Still you need use DB connection with Hierarchy structure,
we request you to share more information to validate further. Kindly share the information below.


  • Specific scenario you have faced the issue(Video demo)
  • Replication steps for reproduce issue.
  • The image of projectInfos data collection of data structure.
  • If possible, replicate the issue in a shared sample and revert back to us.


Once we receive this information, we will be better equipped to identify the root cause of the issue and provide you with the necessary assistance.

Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/GanttSqlServer-945739039.zip

Regards,

Ajithkumar G



MB Mahfoud Bouabdallah February 20, 2024 02:50 PM UTC

Hello Ajithkumar G,

I've included my Visual Studio 2022 solution and a video demonstrating the problem in the attachments. Hopefully, this will help you better understand the issue.



Attachment: SmartUltra_578a2c92.zip


AG Ajithkumar Gopalakrishnan Syncfusion Team February 21, 2024 02:32 PM UTC

Hi Mahfoud,

We are actively addressing your reported query with high priority and will provide an update by or before Feb, 23, 2024. Meanwhile we will contact you if any details required.


Regards,

Ajithkumar G



AG Ajithkumar Gopalakrishnan Syncfusion Team February 23, 2024 12:21 PM UTC

Hi Mahfoud,

We appreciate your patience.

We have validated the provided sample and identified an issue in your code. It seems that the class name for the Gantt chart collection is different from the class name for the subtasks collection. Specifically, the Gantt chart collection class is named ProjectMetallicConstructionGanttDto , while the subtasks collection class is named ProjectMetallicConstructionGanttDetailsDto. This inconsistency in class names might be the cause of the problem where no records are being displayed. To resolve this issue, make sure that both the Gantt chart collection class and the subtasks collection class have consistent and matching names throughout your code. we have attached a code snippet and a sample for reference.

Document link: https://blazor.syncfusion.com/documentation/gantt-chart/data-binding#hierarchical-data-binding

<SfGantt DataSource="@TaskCollection" >

   

</SfGantt>

 

@code {

    private List<TaskData> TaskCollection { get; set; }

   

 

    public class TaskData

    {

        public int TaskId { get; set; }

        public string TaskName { get; set; }

        public DateTime StartDate { get; set; }

        public DateTime? EndDate { get; set; }

        public string Duration { get; set; }

        public int Progress { get; set; }

        public List<TaskData> SubTasks { get; set; }

    }

 

   …

}

 


Sample link: https://blazorplayground.syncfusion.com/embed/LNBpXVrAhGWsRVZO?appbar=true&editor=true&result=true&errorlist=false&theme=bootstrap5

If you have any specific concerns or encounter issues, please provide additional details or share a sample that replicates the problem. We are here to assist you further.

Regards,

Ajithkumar G



MB Mahfoud Bouabdallah replied to Ajithkumar Gopalakrishnan March 1, 2024 06:50 AM UTC

Dear Ajithkumar G,

Apologies for the delayed reply. You're correct, aligning the Gantt chart collection and subtasks collection to the same class has resolved the issue.

Thank you very much



AG Ajithkumar Gopalakrishnan Syncfusion Team March 1, 2024 01:15 PM UTC

Hi Mahfoud,


You are welcome.


We are glad that our solution worked for you.


Please contact us if you require any further assistance.


Regards,

Ajithkumar G


Loader.
Up arrow icon