内置日历
GanttSheet 提供了三种内置日历可供使用:
standard(从上午 8:00 到下午 5:00,周一至周五)
hours24(全天 24 小时,一周七天)
nightShift(从周一晚上 11:00 开始,到周六凌晨 4:00,次日晚上 11:00 至次日上午 8:00)
日历设置
日历设置定义了一些用于计算持续时间的属性。
Week Start - 一周的第一天,默认值为星期日。
Default Start/End Time - 每天的工作开始和结束时间,默认起始时间为上午 8:00,结束时间为下午 5:00。
Hours per day - 一天的工作小时数,默认为 8 小时。
Hours per week - 一周的工作小时数,默认为 40 小时。
Days per month - 一个工作月的天数,默认为 20 天。
Duration Unit - 工作小时的计量单位,默认为天。
Default duration decimal digits - 用于计算的时间精度保留位数,默认为 3。
/*REPLACE_MARKER*/
/*DO NOT DELETE THESE COMMENTS*/
var myTable;
var ganttSheet;
window.onload = function() {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 0 });
initSpread(spread);
initSplitView(spread);
};
function initSpread(spread) {
spread.suspendPaint();
initDataSource(spread);
initGanttSheet(spread);
spread.resumePaint();
}
function initDataSource(spread) {
var tableName = "Gantt_Id";
var baseApiUrl = getBaseApiUrl();
var apiUrl = baseApiUrl + "/" + tableName;
var dataManager = spread.dataManager();
myTable = dataManager.addTable("myTable", {
batch: true,
remote: {
read: {
url: apiUrl
}
},
schema: {
hierarchy: {
type: "Parent",
column: "parentId"
},
columns: {
id: { isPrimaryKey: true },
taskNumber: { dataType: "rowOrder" }
}
}
});
}
function initGanttSheet(spread) {
ganttSheet = spread.addSheetTab(0, "GanttSheet", GC.Spread.Sheets.SheetType.ganttSheet);
var view = myTable.addView("ganttView", [
{ value: "taskNumber", caption: "NO.", width: 60 },
{ value: "name", caption: "Task Name", width: 200 },
{ value: "duration", caption: "Duration", width: 90 },
{ value: "predecessors", caption: "Predecessors", width: 120, visible: false }
]);
view.fetch().then(function() {
ganttSheet.bindGanttView(view);
});
initSidePanel(ganttSheet);
}
function initSidePanel(ganttSheet) {
var currentCalendarItem = document.getElementById("current-calendar");
var startDayItem = document.getElementById("start-day");
var defaultStartTimeItem = document.getElementById("default-start-time");
var defaultFinishTimeItem = document.getElementById("default-finish-time");
var hoursPerDayItem = document.getElementById("hours-per-day");
var hoursPerWeekItem = document.getElementById("hours-per-week");
var daysPerMonthItem = document.getElementById("days-per-month");
var durationUnitItem = document.getElementById("duration-unit");
var decimalDigitsItem = document.getElementById("decimal-digits");
var updateSettingsItem = document.getElementById("update-settings");
currentCalendarItem.addEventListener("change", function() {
var calendarType = currentCalendarItem.value;
var calendar = GC.Spread.Sheets.GanttSheet.Calendar[calendarType];
ganttSheet.project.calendar = calendar;
});
updateSettingsItem.addEventListener("click", function() {
var startDay = Number(startDayItem.value);
var defaultStartTime = defaultStartTimeItem.value;
var defaultFinishTime = defaultFinishTimeItem.value;
var hoursPerDay = Number(hoursPerDayItem.value);
var hoursPerWeek = Number(hoursPerWeekItem.value);
var daysPerMonth = Number(daysPerMonthItem.value);
var durationUnit = durationUnitItem.value;
var decimalDigits = Number(decimalDigitsItem.value);
var project = ganttSheet.project;
ganttSheet.suspendPaint();
project.suspendSchedule();
project.calendarSettings.weekStartOn = startDay;
var startTime = defaultStartTime.split(":");
project.calendarSettings.defaultStartTime = { hour: Number(startTime[0]), minute: Number(startTime[1]) };
var finishTime = defaultFinishTime.split(":");
project.calendarSettings.defaultFinishTime = { hour: Number(finishTime[0]), minute: Number(finishTime[1]) };
project.calendarSettings.hoursPerDay = hoursPerDay;
project.calendarSettings.hoursPerWeek = hoursPerWeek;
project.calendarSettings.daysPerMonth = daysPerMonth;
project.calendarSettings.defaultDurationUnit = durationUnit;
project.calendarSettings.defaultDurationDecimalDigits = decimalDigits;
project.resumeSchedule();
ganttSheet.resumePaint();
});
}
function getBaseApiUrl() {
return window.location.href.match(/http.+spreadjs\/SpreadJSTutorial\//)[0] + 'server/api';
}
function initSplitView(spread) {
var host = document.getElementById("split-view");
var content = host.getElementsByClassName("split-content")[0];
var panel = host.getElementsByClassName("split-panel")[0];
new SplitView({
host: host,
content: content,
panel: panel,
refreshContent: function() {
spread.refresh();
}
});
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<meta name="spreadjs culture" content="zh-cn" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css"
href="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/spread/source/splitView/splitView.css">
<!-- Promise Polyfill for IE, https://www.npmjs.com/package/promise-polyfill -->
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
<script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/dist/gc.spread.sheets.all.min.js"
type="text/javascript"></script>
<script
src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-tablesheet/dist/gc.spread.sheets.tablesheet.min.js"
type="text/javascript"></script>
<script
src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-ganttsheet/dist/gc.spread.sheets.ganttsheet.min.js"
type="text/javascript"></script>
<script
src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-resources-zh/dist/gc.spread.sheets.resources.zh.min.js"
type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/splitView/splitView.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div id="split-view" class="sample-tutorial">
<div id="ss" class="sample-spreadsheets split-content"></div>
<div class="options-container split-panel">
<div class="option-block">
<div class="option-row option-title">
Config the calendar.
</div>
<div class="option-row selection-box">
<label for="current-calendar">Current Calendar</label>
<select id="current-calendar">
<option value="standard" selected="selected">Standard</option>
<option value="hours24">24 Hours</option>
<option value="nightShift">Night Shift</option>
</select>
</div>
</div>
<div class="option-block">
<div class="option-row selection-box">
<label for="start-day">Week Starts On</label>
<select id="start-day">
<option value="0" selected="selected">Sunday</option>
<option value="1">Monday</option>
<option value="2">Tuesday</option>
<option value="3">Wednesday</option>
<option value="4">Thursday</option>
<option value="5">Friday</option>
<option value="6">Saturday</option>
</select>
</div>
<div class="option-row input-box">
<label for="default-start-time">Default Start Time</label>
<input type="text" id="default-start-time" value="8:00" />
<div class="option-info valid">* valid value: 24HR, format 8:00</div>
</div>
<div class="option-row input-box">
<label for="default-finish-time">Default Finish Time</label>
<input type="text" id="default-finish-time" value="17:00" />
<div class="option-info valid">* valid value: 24HR, format 17:00</div>
</div>
<div class="option-row input-box">
<label for="hours-per-day">Hours Per Day</label>
<input type="text" id="hours-per-day" value="8" />
<div class="option-info valid">* valid value: number</div>
</div>
<div class="option-row input-box">
<label for="hours-per-week">Hours Per Week</label>
<input type="text" id="hours-per-week" value="40" />
<div class="option-info valid">* valid value: number</div>
</div>
<div class="option-row input-box">
<label for="days-per-month">Days Per Month</label>
<input type="text" id="days-per-month" value="20" />
<div class="option-info valid">* valid value: number</div>
</div>
<div class="option-row selection-box">
<label for="duration-unit">Duration Unit</label>
<select id="duration-unit">
<option value="Month">Month</option>
<option value="Week">Week</option>
<option value="Day" selected>Day</option>
<option value="Hour">Hour</option>
<option value="Minute">Minute</option>
</select>
</div>
<div class="option-row input-box">
<label for="decimal-digits">Duration Decimal Digits</label>
<input type="text" id="decimal-digits" value="3" />
<div class="option-info valid">* valid value: number</div>
</div>
<div class="option-row">
<input type="button" id="update-settings" class="option-button" value="Update Settings" />
</div>
</div>
</div>
</div>
</html>
.option-block {
background: #fff;
padding: 8px;
margin: 12px 0;
border-radius: 4px;
border: 1px dashed #82bc00;
box-shadow: 0px 0 6px 0 rgba(0,0,0,0.1);
}
.option-block.toggle {
border: 1px dotted #f7a711;
}
.option-row {
font-size: 14px;
box-sizing: border-box;
padding: 4px 0;
}
.option-title {
font-weight: bold;
color: #656565;
}
.option-info {
font-size: 12px;
color: #919191;
margin-top: 6px;
font-weight: normal;
}
.option-info.valid {
color: #82bc00;
}
.option-info.toggle {
color: #f7a711;
}
.option-button {
width: 100%;
padding: 0;
line-height: 20px;
background: #82bc00;
color: #fff;
transition: 0.3s;
cursor: pointer;
outline: none;
border-radius: 4px;
box-sizing: border-box;
box-shadow: 0 1px 4px 0 rgba(0,0,0,0.3);
border: none;
}
.option-button:hover {
background: #82bc00;
color: #fff;
box-shadow: 0 3px 8px 0 rgba(0,0,0,0.4);
}
.option-checkbox {
background: #fff;
border: 1px dashed #f7a711;
color: #f7a711;
padding: 2px 4px;
transition: 0.3s;
box-sizing: border-box;
cursor: pointer;
}
.option-checkbox.active {
color: #fff;
background: #f7a711;
box-shadow: 0 1px 4px 0 rgba(0,0,0,0.3);
border-radius: 4px;
}
.selection-box {
position: relative;
}
.selection-box > select {
text-align: left;
width: 100%;
height: 20px;
padding: 0;
line-height: 20px;
background: transparent;
border: none;
border-bottom: 2px solid #656565;
color: #656565;
transition: 0.3s;
cursor: pointer;
outline: none;
box-sizing: border-box;
}
.selection-box > select > option {
background: white;
}
.selection-box > select:focus {
border-bottom: 2px solid #82bc00;
color: #82bc00;
box-shadow: 0 2px 6px 0 rgba(0,0,0,0.3);
}
.selection-box > label {
position: absolute;
cursor: pointer;
font-size: 12px;
color: #fff;
background: #656565;
padding: 0 4px;
right: 0;
top: 6px;
box-shadow: 0 1px 4px 0 rgba(0,0,0,0.3);
}
.input-box {
position: relative;
}
.input-box > input[type=text] {
width: 100%;
background: transparent;
border: none;
color: #656565;
border-bottom: 2px solid #656565;
outline: none;
box-sizing: border-box;
transition: 0.3s;
}
.input-box > input[type=text]:focus {
color: #82bc00;
border-bottom: 2px solid #82bc00;
}
.input-box > label {
cursor: pointer;
position: absolute;
right: 0;
top: 5px;
font-size: 12px;
color: #fff;
background: #656565;
padding: 0 4px;
box-shadow: 0 1px 4px 0 rgba(0,0,0,0.3);
}