[]
To create a GanttSheet, follow the below steps:
Add the following script files to use the GanttSheet.
<script src='.../spreadjs/gc.spread.sheets.all.x.x.x.min.js' type='text/javascript'></script>
<script src='.../spreadjs/plugins/gc.spread.sheets.tablesheet.x.x.x.min.js' type='text/javascript'></script>
<script src='.../spreadjs/plugins/gc.spread.sheets.ganttsheet.x.x.x.min.js' type='text/javascript'></script>
Generate a spread container, then add a sheet tab with the ganttSheet type.
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("spread");
var ganttSheet = spread.addSheetTab(0, "GanttSheet", GC.Spread.Sheets.SheetType.ganttSheet);
Initialize the data manager using the DataManager method.
var dataManager = spread.dataManager();
Add a table in the Data Manager using the addTable method. This method accepts the table name as a string and the IDataSourceOption interface options.
var myTable1 = dataManager.addTable("myTable1", {
batch: true,
remote: {
read: {
url: apiUrl
}
},
Note: Since the data has a relation to the GanttSheet, you should use batch mode to save them.
Define the required hierarchy schema based on your data source structure.
schema: {
hierarchy: {
type: "Parent",
column: "parentId"
},
columns: {
id: { isPrimaryKey: true },
taskNumber: { dataType: "rowOrder" }
}
}
To know more about different hierarchy types, please refer to the "Hierarchy Types" page.
Add a view to the table of the Data Manager using the addView method and define column info to initialize a GanttSheet.
ganttSheet = spread.addSheetTab(0, "GanttSheet1",
GC.Spread.Sheets.SheetType.ganttSheet);
var view = myTable1.addView("myView1", [
{ 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}
]);
Fetch using the fetch method of the Data Manager table and then bind the fetched view to the GanttSheet using the bindGanttView method.
view.fetch().then(function () {
ganttSheet.bindGanttView(view);
});