1
+ @Html.EJS().Gantt("Gantt").DataSource((IEnumerable < object >)ViewBag.DataSource).Height("450px").AllowSelection(true).TreeColumnIndex(1)
2
+ .TaskFields(ts => ts.Id("TaskId").Name("TaskName").StartDate("StartDate").EndDate("EndDate").Duration("Duration").Progress("Progress")
3
+ .Dependency("Predecessor").Child("SubTasks")).TimelineTemplate("#TimelineTemplates").TimelineSettings(ts => ts.TimelineUnitSize(100).TopTier(tt => tt.Unit(Syncfusion.EJ2.Gantt.TimelineViewMode.Week).Format("MMM dd, yyyy"))
4
+ .BottomTier(bt => bt.Unit(Syncfusion.EJ2.Gantt.TimelineViewMode.Day).Count(1)))
5
+ {
6
+ col.Field("TaskId").Visible(false).Add();
7
+ col.Field("TaskName").Width(300).Add();
8
+ col.Field("StartDate").Add();
9
+ col.Field("EndDate").Add();
10
+ col.Field("Duration").Add();
11
+ col.Field("Progress").Add();
12
+ })
13
+ .LabelSettings(ls => ls.LeftLabel("TaskName"))
14
+ .SplitterSettings(sp => sp.ColumnIndex(1))
15
+ .ProjectStartDate("03/31/2024")
16
+ .ProjectEndDate("04/23/2024")
17
+ .Holidays(hol => {
18
+ hol.From("04/04/2019").To("04/05/2019").Label("Local Holiday").Add();
19
+ hol.From("04/12/2019").To("04/12/2019").Label("Public holiday").Add();
20
+ })
21
+ .Render()
22
+ <script type="text/x-jsrender" id="TimelineTemplates">
23
+ ${if(tier == 'topTier')}
24
+ <div class="e-header-cell-label e-gantt-top-cell-text" style="width:100%;background-color: #FBF9F1 ; font-weight: bold;height: 100%;display: flex; justify-content: center ; align-items: center; "title=${date}>
25
+ <div> ${value}</div>
26
+ <div style="width:20px; height: 20px; line-height: normal; padding-left: 10px; ">
27
+ <img style="width:100%; height:100%;" src =${imagedate()} >
28
+ </div>
29
+ </div>
30
+ ${/if}
31
+ ${if(tier == 'bottomTier')}
32
+ <div class="e-header-cell-label e-gantt-top-cell-text" style="width:100%;background-color: ${bgColor(value,date)}; text-align: center;height: 100%;display: flex; align-items: center; font-weight: bold;justify-content: center "title=${date}>
33
+ ${holidayValue(value,date)}
34
+ </div>
35
+ ${/if}
36
+
37
+ </script>
38
+
39
+ <script>
40
+ const holidayValue = (value, date) => {
41
+ var ganttObj = document.getElementById("Gantt").ej2_instances[0];
42
+ const parsedDate = new Date(date);
43
+ for (let i = 0; i < ganttObj.holidays.length; i++) {
44
+ const holiday = ganttObj.holidays[i];
45
+ const fromDate = new Date(holiday.from);
46
+ const toDate = new Date(holiday.to)
47
+ if (parsedDate >= fromDate && parsedDate <= toDate) {
48
+ const options = { weekday: 'short' };
49
+ return parsedDate.toLocaleDateString('en-US', options).toLocaleUpperCase();
50
+ }
51
+ }
52
+ return value
53
+ }
54
+
55
+ const imagedate = () => {
56
+ const getImage = Math.floor(Math.random() * 5) + 1;
57
+ return "./image/" + getImage + ".svg";
58
+
59
+ }
60
+ const bgColor = (value, date) => {
61
+ if (value === "S") {
62
+ return "#7BD3EA"
63
+ }
64
+ var ganttObj = document.getElementById("Gantt").ej2_instances[0];
65
+ const parsedDate = new Date(date);
66
+ for (let i = 0; i < ganttObj.holidays.length; i++) {
67
+ const holiday = ganttObj.holidays[i];
68
+ const fromDate = new Date(holiday.from);
69
+ const toDate = new Date(holiday.to)
70
+ if (parsedDate >= fromDate && parsedDate <= toDate) {
71
+ return "#97E7E1";
72
+ }
73
+ }
74
+ return "#E0FBE2"
75
+ };
76
+ </script>
0 commit comments