|
| 1 | +@page "/" |
| 2 | +@rendermode InteractiveServer |
| 3 | +@using Syncfusion.Blazor |
| 4 | +@using Syncfusion.Blazor.Data |
| 5 | +@using Syncfusion.Blazor.Gantt |
| 6 | +@using GanttGraphQL.Models |
| 7 | + |
| 8 | +<SfGantt TValue="TaskDataModel" |
| 9 | + Height="560px" |
| 10 | + Width="100%" |
| 11 | + AllowFiltering="true" |
| 12 | + AllowSorting="true" |
| 13 | + TreeColumnIndex="1" |
| 14 | + EnableContextMenu="true" |
| 15 | + Toolbar="@ToolbarItems"> |
| 16 | + |
| 17 | + <SfDataManager Url="https://localhost:7000/graphql" |
| 18 | + Adaptor="Adaptors.GraphQLAdaptor" |
| 19 | + GraphQLAdaptorOptions="@AdaptorOptions"> |
| 20 | + </SfDataManager> |
| 21 | + |
| 22 | + <GanttTaskFields Id="@nameof(TaskDataModel.TaskID)" Name="@nameof(TaskDataModel.TaskName)" StartDate="@nameof(TaskDataModel.StartDate)" |
| 23 | + EndDate="@nameof(TaskDataModel.EndDate)" Duration="@nameof(TaskDataModel.Duration)" Progress="@nameof(TaskDataModel.Progress)" |
| 24 | + Dependency="@nameof(TaskDataModel.Predecessor)" ParentID="@nameof(TaskDataModel.ParentID)"> |
| 25 | + </GanttTaskFields> |
| 26 | + |
| 27 | + <GanttColumns> |
| 28 | + <GanttColumn Field="@nameof(TaskDataModel.TaskID)" HeaderText="Task ID" IsPrimaryKey="true" Width="110"></GanttColumn> |
| 29 | + <GanttColumn Field="@nameof(TaskDataModel.TaskName)" HeaderText="Task Name" Width="240"></GanttColumn> |
| 30 | + <GanttColumn Field="@nameof(TaskDataModel.StartDate)" HeaderText="Start Date" Format="d" Width="140"></GanttColumn> |
| 31 | + <GanttColumn Field="@nameof(TaskDataModel.EndDate)" HeaderText="End Date" Format="d" Width="140"></GanttColumn> |
| 32 | + <GanttColumn Field="@nameof(TaskDataModel.Duration)" HeaderText="Duration" Width="130"></GanttColumn> |
| 33 | + <GanttColumn Field="@nameof(TaskDataModel.Progress)" HeaderText="Progress" Width="130"> |
| 34 | + <Template> |
| 35 | + @{ |
| 36 | + var taskRecord = context as TaskDataModel; |
| 37 | + if (taskRecord == null) return; |
| 38 | + |
| 39 | + string progressText = $"{taskRecord.Progress}%"; |
| 40 | + } |
| 41 | + <div class="e-progress-custom"> |
| 42 | + <div class="e-progress-outer"> |
| 43 | + <div class="e-progress-bar" style="width:@(taskRecord.Progress)%;"> |
| 44 | + </div> |
| 45 | + </div> |
| 46 | + <div class="e-progress-inner"> |
| 47 | + <span>@progressText</span> |
| 48 | + </div> |
| 49 | + </div> |
| 50 | + </Template> |
| 51 | + </GanttColumn> |
| 52 | + <GanttColumn Field="@nameof(TaskDataModel.Predecessor)" HeaderText="Predecessor" Width="200"> |
| 53 | + |
| 54 | + <Template> |
| 55 | + @{ |
| 56 | + var task = context as TaskDataModel; |
| 57 | + var value = task?.Predecessor; |
| 58 | + |
| 59 | + if (!string.IsNullOrWhiteSpace(value)) |
| 60 | + { |
| 61 | + <div class="e-dependencies">@value</div> |
| 62 | + ; |
| 63 | + } |
| 64 | + else |
| 65 | + { |
| 66 | + <div> - </div> |
| 67 | + ; |
| 68 | + } |
| 69 | + } |
| 70 | + </Template> |
| 71 | + </GanttColumn> |
| 72 | + </GanttColumns> |
| 73 | + <GanttEditSettings AllowEditing="true" AllowTaskbarEditing="true" AllowAdding="true" AllowDeleting="true" /> |
| 74 | +</SfGantt> |
| 75 | +@code { |
| 76 | + |
| 77 | + public List<object> ToolbarItems = new() { "Add", "Edit", "Update", "Delete", "Search" }; |
| 78 | + |
| 79 | + // GraphQL adaptor configuration: ResolverName must match your server method (PascalCase) |
| 80 | + // and the query must select count + result with the fields the Gantt needs. |
| 81 | + private Syncfusion.Blazor.Data.GraphQLAdaptorOptions AdaptorOptions => new() |
| 82 | + { |
| 83 | + ResolverName = "TaskData", |
| 84 | + Query = @" |
| 85 | + query TaskData($dataManager: DataManagerRequestInput!) { |
| 86 | + taskData(dataManager: $dataManager) { |
| 87 | + count |
| 88 | + result { |
| 89 | + taskID |
| 90 | + taskName |
| 91 | + startDate |
| 92 | + endDate |
| 93 | + duration |
| 94 | + progress |
| 95 | + predecessor |
| 96 | + parentID |
| 97 | + } |
| 98 | + } |
| 99 | + }", |
| 100 | + |
| 101 | + Mutation = new Syncfusion.Blazor.Data.GraphQLMutation |
| 102 | + { |
| 103 | + // INSERT (matches InsertTask parameters) |
| 104 | + Insert = @" |
| 105 | + mutation create($record: TaskDataModelInput!, $index: Int!, $action: String!, $additionalParameters: Any) { |
| 106 | + createTask(record: $record, index: $index, action: $action, additionalParameters: $additionalParameters) { |
| 107 | + taskID |
| 108 | + taskName |
| 109 | + startDate |
| 110 | + endDate |
| 111 | + duration |
| 112 | + progress |
| 113 | + predecessor |
| 114 | + parentID |
| 115 | + } |
| 116 | + }", |
| 117 | + Update = @"mutation update($record: TaskDataModelInput!, $action: String!, $primaryColumnName: String!, $primaryColumnValue: Int!, $additionalParameters: Any) { |
| 118 | + updateTask(record: $record, action: $action, primaryColumnName: $primaryColumnName, primaryColumnValue: $primaryColumnValue, additionalParameters: $additionalParameters) { |
| 119 | + taskID taskName startDate endDate duration progress predecessor parentID |
| 120 | + } |
| 121 | + }", |
| 122 | + |
| 123 | + // DELETE (matches DeleteTask parameters) |
| 124 | + Delete = @"mutation delete($primaryColumnValue: ID!, $additionalParameters: Any) { |
| 125 | + deleteTask(key: $primaryColumnValue, additionalParameters: $additionalParameters) |
| 126 | + }", |
| 127 | + Batch = @"mutation batch($changed: [TaskDataModelInput!], $added: [TaskDataModelInput!], $deleted: [TaskDataModelInput!], $action: String!, $primaryColumnName: String!, $additionalParameters: Any, $dropIndex: Int) { |
| 128 | + batchUpdate(changed: $changed, added: $added, deleted: $deleted, action: $action, primaryColumnName: $primaryColumnName, additionalParameters: $additionalParameters, dropIndex: $dropIndex) { |
| 129 | + taskID |
| 130 | + taskName |
| 131 | + startDate |
| 132 | + endDate |
| 133 | + duration |
| 134 | + progress |
| 135 | + predecessor |
| 136 | + parentID |
| 137 | + } |
| 138 | + }" |
| 139 | + } |
| 140 | + }; |
| 141 | +} |
| 142 | + |
| 143 | +<style> |
| 144 | + .e-progress-custom { |
| 145 | + display: flex; |
| 146 | + align-items: center; |
| 147 | + gap: 8px; |
| 148 | + } |
| 149 | +
|
| 150 | + .e-progress-outer { |
| 151 | + width: 120px; |
| 152 | + height: 8px; |
| 153 | + border-radius: 4px; |
| 154 | + background: #e0e0e0; |
| 155 | + position: relative; |
| 156 | + overflow: hidden; |
| 157 | + } |
| 158 | +
|
| 159 | + .e-progress-bar { |
| 160 | + height: 100%; |
| 161 | + background: #3b82f6; |
| 162 | + } |
| 163 | +
|
| 164 | + .e-progress-inner span { |
| 165 | + font-size: 12px; |
| 166 | + } |
| 167 | +
|
| 168 | + /* Keep visibility when row selected */ |
| 169 | + .e-row.e-active .e-progress-outer, |
| 170 | + .e-row.e-selectionbackground .e-progress-outer { |
| 171 | + background: #cfcfcf; |
| 172 | + } |
| 173 | +
|
| 174 | + .e-row.e-active .e-progress-bar, |
| 175 | + .e-row.e-selectionbackground .e-progress-bar { |
| 176 | + background: #2563eb; |
| 177 | + } |
| 178 | +
|
| 179 | + .e-dependencies { |
| 180 | + border-radius: 4px; |
| 181 | + padding: 2px 8px; |
| 182 | + width: fit-content; |
| 183 | + border: 1px solid #b8b8b8; |
| 184 | + font-weight: 400; |
| 185 | + font-size: 14px; |
| 186 | + line-height: 20px; |
| 187 | + margin: 0 auto; |
| 188 | + } |
| 189 | +
|
| 190 | + .e-row.e-active .e-dependencies, |
| 191 | + .e-row.e-selectionbackground .e-dependencies { |
| 192 | + background: #e5e7eb; |
| 193 | + } |
| 194 | +
|
| 195 | +</style> |
0 commit comments