개요

TableSheet는 데이터 소스 스키마에서 계층 구조 옵션으로 구성할 수 있는 계층 구조 데이터를 지원합니다.

데이터 소스 스키마의 옵션: 계층 구조에는 Parent, Level, ChildrenPath, Custom 등 4가지 계층 구조 유형이 있습니다. 표를 데이터 관리자에 추가하는 경우 각각을 구성할 수 있습니다. Parent 계층 구조 유형 구성: Level 계층 구조 유형 구성: ChildrenPath 계층 구조 유형 구성: Custom 계층 구조 유형 구성: TableSheet에서 계층 구조 레코드를 업데이트하는 몇 가지 작업이 있습니다. 레코드 승격: 레코드 강등: 위로 이동: 아래로 이동: 지정된 행 앞에 새 행 데이터 추가: 지정된 행 뒤에 새 행 데이터 추가: 지정된 행의 부모로 새 행 데이터 추가: 지정된 행의 자식으로 새 행 데이터 추가: 모든 계층 구조 수준 확장: 모든 계층 구조 수준 축소: 지정된 수준으로 계층 구조 데이터 확장: TableSheet 옵션에서 계층 구조 레코드에 대한 메뉴 항목의 표시 여부를 전환하는 몇 가지 옵션이 있습니다. TableSheet에 계층 구조 메뉴 항목 표시하기:
window.onload = function() { var spread = new GC.Spread.Sheets.Workbook(_getElementById('ss'), { sheetCount: 0 }); initSpread(spread); }; function initSpread(spread) { spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader; spread.clearSheets(); var dataManager = spread.dataManager(); initHierarchyParentType(spread, dataManager); initHierarchyLevelType(spread, dataManager); initHierarchyCustomType(spread, dataManager); initHierarchyChildrenType(spread, dataManager); } function initHierarchyParentType(spread, dataManager) { var apiUrl = getBaseApiUrl() + "/Hierarchy_Data"; var table = dataManager.addTable("hierarchyParentTable", { remote: { read: { url: apiUrl } }, autoSync: true, schema: { hierarchy: { type: 'Parent', // config the parent hierarchy type column: 'TaskParentId', // specify the column that could be used for building hierarchical view }, columns: { 'TaskId':{ dataName: 'id', isPrimaryKey: true}, // the primary key is required 'TaskParentId':{ dataName: 'parentId'}, 'TaskTitle':{ dataName: 'title'}, 'TaskOwner':{ dataName: 'owner'}, 'StartDate':{ dataName: 'startDate'}, 'DueDate':{ dataName: 'dueDate'}, 'TaskComplete':{ dataName: 'complete'}, 'TaskOrder':{ dataName: 'rowOrder', dataType: 'rowOrder'}, // if dataType be rowOrder, the records could be moved and added } } }); var sheet = spread.addSheetTab(0, "HierarchyParent", GC.Spread.Sheets.SheetType.tableSheet); sheet.setDefaultRowHeight(40, GC.Spread.Sheets.SheetArea.colHeader); sheet.options.allowAddNew = true; // show the menu items for hierarchical records sheet.options.menuItemVisibility = { // the options below be on the row header promoteMenuItemVisible: true, demoteMenuItemVisible: true, // the options below be on the column header expandAllLevelMenuItemVisible: true, collapseAllLevelMenuItemVisible: true, expandToLevelMenuItemVisible: true, // the options below be on the row header // and the menu items be enable for the dataType of the column be rowOrder moveUpMenuItemVisible: true, moveDownMenuItemVisible: true, addBeforeMenuItemVisible: true, addAfterMenuItemVisible: true, addAboveMenuItemVisible: true, addBelowMenuItemVisible: true, }; table.fetch().then(function () { var myView = table.addView("myView", [ { value: "TaskTitle", width: 200, outlineColumn: { showImage: true, images: ['$DEMOROOT$/spread/source/images/task-1.png', '$DEMOROOT$/spread/source/images/task-2.png', '$DEMOROOT$/spread/source/images/task-3.png'], expandIndicator: '$DEMOROOT$/spread/source/images/increaseIndicator.png', collapseIndicator: '$DEMOROOT$/spread/source/images/decreaseIndicator.png', } }, { value: "TaskOwner", width: 200 }, { value: "StartDate", width: 200 }, { value: "DueDate", width: 200 }, { value: "TaskComplete", width: 200 }, ]); spread.suspendPaint(); sheet.setDataView(myView); spread.resumePaint(); }); } function initHierarchyLevelType(spread, dataManager) { var apiUrl = getBaseApiUrl() + "/Hierarchy_Data/level"; var table = dataManager.addTable("hierarchyLevelTable", { remote: { read: { url: apiUrl }, create: { url: apiUrl }, update: { url: apiUrl, method: 'PUT' }, delete: { url: apiUrl }, batch: { url: apiUrl } }, batch: true, // autoSync: true, schema: { hierarchy: { type: 'Level', // config the level hierarchy type column: 'level', outlineColumn: { // the outline column could be set in the hierarchy value: "TaskTitle", showImage: true, images: ['$DEMOROOT$/spread/source/images/task-1.png', '$DEMOROOT$/spread/source/images/task-2.png', '$DEMOROOT$/spread/source/images/task-3.png'], expandIndicator: '$DEMOROOT$/spread/source/images/increaseIndicator.png', collapseIndicator: '$DEMOROOT$/spread/source/images/decreaseIndicator.png', } }, columns: { 'TaskTitle': { dataName: 'title' }, 'TaskOwner': { dataName: 'owner' }, 'StartDate': { dataName: 'startDate' }, 'DueDate': { dataName: 'dueDate' }, 'TaskComplete': { dataName: 'complete' }, } } }); var sheet = spread.addSheetTab(1, "HierarchyLevel", GC.Spread.Sheets.SheetType.tableSheet); sheet.setDefaultRowHeight(40, GC.Spread.Sheets.SheetArea.colHeader); sheet.options.allowAddNew = true; sheet.options.menuItemVisibility = { promoteMenuItemVisible: true, demoteMenuItemVisible: true, expandAllLevelMenuItemVisible: true, collapseAllLevelMenuItemVisible: true, expandToLevelMenuItemVisible: true, moveUpMenuItemVisible: true, moveDownMenuItemVisible: true, addBeforeMenuItemVisible: true, addAfterMenuItemVisible: true, addAboveMenuItemVisible: true, addBelowMenuItemVisible: true, }; table.fetch().then(function () { var myView = table.addView("myView", [ { value: "TaskTitle", width: 200 }, { value: "TaskOwner", width: 200 }, { value: "StartDate", width: 200 }, { value: "DueDate", width: 200 }, { value: "TaskComplete", width: 200 }, ]); spread.suspendPaint(); sheet.setDataView(myView); spread.resumePaint(); }); } function initHierarchyChildrenType(spread, dataManager) { var apiUrl = getBaseApiUrl() + "/Hierarchy_Data/children"; var table = dataManager.addTable("hierarchyChildrenTable", { remote: { read: { url: apiUrl }, create: { url: apiUrl }, update: { url: apiUrl, method: 'PUT' }, delete: { url: apiUrl }, batch: { url: apiUrl } }, batch: true, // autoSync: true, schema: { hierarchy: { type: 'ChildrenPath', // config the children path hierarchy type column: 'children', }, columns: { 'TaskTitle':{ dataName: 'title'}, 'TaskOwner':{ dataName: 'owner'}, 'StartDate':{ dataName: 'startDate'}, 'DueDate':{ dataName: 'dueDate'}, 'TaskComplete':{ dataName: 'complete'}, } } }); var sheet = spread.addSheetTab(2, "HierarchyChildren", GC.Spread.Sheets.SheetType.tableSheet); sheet.setDefaultRowHeight(40, GC.Spread.Sheets.SheetArea.colHeader); sheet.options.allowAddNew = true; sheet.options.menuItemVisibility = { promoteMenuItemVisible: true, demoteMenuItemVisible: true, expandAllLevelMenuItemVisible: true, collapseAllLevelMenuItemVisible: true, expandToLevelMenuItemVisible: true, moveUpMenuItemVisible: true, moveDownMenuItemVisible: true, addBeforeMenuItemVisible: true, addAfterMenuItemVisible: true, addAboveMenuItemVisible: true, addBelowMenuItemVisible: true, }; table.fetch().then(function () { var myView = table.addView("myView", [ { value: "TaskTitle", width: 200, outlineColumn: true }, { value: "TaskOwner", width: 200 }, { value: "StartDate", width: 200 }, { value: "DueDate", width: 200 }, { value: "TaskComplete", width: 200 }, ]); spread.suspendPaint(); sheet.setDataView(myView); spread.resumePaint(); }); } function initHierarchyCustomType(spread, dataManager) { var apiUrl = getBaseApiUrl() + "/Hierarchy_Data"; var table = dataManager.addTable("hierarchyCustomTable", { remote: { read: { url: apiUrl } }, autoSync: true, schema: { hierarchy: { type: 'Custom', // config the custom hierarchy type column: 'WBSNumber', parse: function (options) { // parsing the key to the parent key that be similar as the parent hierarchy type let segments = options.data.WBSNumber.split('.'); return segments.slice(0, segments.length - 1).join('.'); }, unparse: function (options) { // if the key should be updated, unparse the related data to the key let parentIds, currentIndex = options.index, parentData = options.parentData, parentKey = parentData && parentData.WBSNumber; if (parentKey) { let sp = parentKey.split('.'); parentIds = sp; } else { parentIds = []; } parentIds.push(currentIndex + 1); return parentIds.join('.'); } }, columns: { 'WBSNumber': { dataName: 'wbs', isPrimaryKey: true }, 'TaskTitle': { dataName: 'title' }, 'TaskOwner': { dataName: 'owner' }, 'StartDate': { dataName: 'startDate' }, 'DueDate': { dataName: 'dueDate' }, 'TaskComplete': { dataName: 'complete' }, } } }); var sheet = spread.addSheetTab(3, "HierarchyCustom", GC.Spread.Sheets.SheetType.tableSheet); sheet.setDefaultRowHeight(40, GC.Spread.Sheets.SheetArea.colHeader); sheet.options.allowAddNew = true; sheet.options.menuItemVisibility = { promoteMenuItemVisible: true, demoteMenuItemVisible: true, expandAllLevelMenuItemVisible: true, collapseAllLevelMenuItemVisible: true, expandToLevelMenuItemVisible: true, }; table.fetch().then(function () { var myView = table.addView("myView", [ { value: "WBSNumber", width: 200, outlineColumn: true }, { value: "TaskTitle", width: 200 }, { value: "TaskOwner", width: 200 }, { value: "StartDate", width: 200 }, { value: "DueDate", width: 200 }, { value: "TaskComplete", width: 200 }, ]); spread.suspendPaint(); sheet.setDataView(myView); spread.resumePaint(); }); } function _getElementById(id) { return document.getElementById(id); } function getBaseApiUrl() { return window.location.href.match(/http.+spreadjs\/learn-spreadjs\//)[0] + 'server/api'; }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="ko-kr"/> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets-resources-ko/dist/gc.spread.sheets.resources.ko.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/data/outlineColumn-wbs.js" type="text/javascript"></script> <script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets-tablesheet/dist/gc.spread.sheets.tablesheet.min.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 class="sample-tutorial"> <div id="ss" class="sample-spreadsheets"></div> </div></body> </html>
.colorLabel { background-color: #F4F8EB; } .rightAlignLabel { width: 120px; text-align: right; margin-right: 8px; } input[type="text"] { width: 190px; } .sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: 100%; height: 100%; overflow: hidden; float: left; } .options-container { float: right; width: 280px; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } .option-row { font-size: 14px; padding: 5px; margin-top: 10px; } label { margin-bottom: 6px; } input { padding: 4px 6px; } input[type=button] { margin-top: 6px; width: 190px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }