사용법
다음 코드는 워크시트에서 계층 구조가 있는 TableSheet를 렌더링하는 방법을 보여줍니다.
이 데모의 기능
계층 구조
컨텍스트 메뉴
<template>
<div class="sample-tutorial">
<gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread">
</gc-spread-sheets>
</div>
</template>
<script setup>
import GC from "@mescius/spread-sheets";
import { ref, toRaw } from "vue";
import '@mescius/spread-sheets-shapes';
import '@mescius/spread-sheets-datacharts-addon';
import "@mescius/spread-sheets-tablesheet";
import '@mescius/spread-sheets-resources-ko';
GC.Spread.Common.CultureManager.culture("ko-kr");
const spreadRef = ref(null);
function initSpread(spread) {
spread.suspendPaint();
var sheet = spread.getActiveSheet();
initTableSheet(spread, function (tableSheet) {
spread.setActiveSheet(sheet.name());
var dataRange = registerTableSheetIntoWorksheet(tableSheet, sheet);
beautifySheet(sheet, dataRange);
spread.undoManager().clear();
});
spread.resumePaint();
}
async function initTableSheet(spread, callback) {
spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader;
//init a data manager
var dataManager = 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 tableSheet = spread.addSheetTab(0, "HierarchyParent", GC.Spread.Sheets.SheetType.tableSheet);
tableSheet.setDefaultRowHeight(40, GC.Spread.Sheets.SheetArea.colHeader);
tableSheet.options.allowAddNew = true;
// show the menu items for hierarchical records
tableSheet.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,
};
await table.fetch();
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();
tableSheet.setDataView(myView);
callback && callback(tableSheet);
spread.resumePaint();
return tableSheet;
}
function registerTableSheetIntoWorksheet(tableSheet, sheet) {
var name = tableSheet.name() + "_DataRange";
var row = 1;
var col = 1;
var dataRange = sheet.dataRanges.add(name, tableSheet.name(), new GC.Spread.Sheets.Range(row, col, -1, -1));
return dataRange;
}
function beautifySheet(sheet, dataRange) {
var range = dataRange.range();
for (var i = range.row; i < range.row + range.rowCount; i++) {
sheet.autoFitRow(i);
}
for (var i = range.col; i < range.col + range.colCount; i++) {
sheet.autoFitColumn(i);
}
sheet.setColumnWidth(1, 30);
}
function getBaseApiUrl() {
return window.location.href.match(/http.+spreadjs\/learn-spreadjs\//)[0] + 'server/api';
}
</script>
<style scoped>
#app {
height: 100%;
}
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: 100%;
height: 100%;
overflow: hidden;
float: left;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
<!DOCTYPE html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>SpreadJS VUE</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css"
href="$DEMOROOT$/ko/vue3/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/spread/source/splitView/splitView.css">
<script src="$DEMOROOT$/ko/vue3/node_modules/systemjs/dist/system.src.js"></script>
<script src="./systemjs.config.js"></script>
<script src="./compiler.js" type="module"></script>
<script src="$DEMOROOT$/spread/source/splitView/SplitView.js"></script>
<script>
var System = SystemJS;
System.import("./src/app.js");
System.import('$DEMOROOT$/ko/lib/vue3/license.js');
</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
(function (global) {
SystemJS.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
packageConfigPaths: [
'./node_modules/*/package.json',
"./node_modules/@mescius/*/package.json",
"./node_modules/@babel/*/package.json",
"./node_modules/@vue/*/package.json"
],
map: {
'vue': "npm:vue/dist/vue.esm-browser.js",
'tiny-emitter': 'npm:tiny-emitter/index.js',
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
"systemjs-babel-build": "npm:systemjs-plugin-babel/systemjs-babel-browser.js",
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-resources-ko': 'npm:@mescius/spread-sheets-resources-ko/index.js',
'@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/index.js',
'@mescius/spread-sheets-shapes': 'npm:@mescius/spread-sheets-shapes/index.js',
'@mescius/spread-sheets-datacharts-addon': 'npm:@mescius/spread-sheets-datacharts-addon/index.js',
'@mescius/spread-sheets-tablesheet': 'npm:@mescius/spread-sheets-tablesheet/index.js',
},
meta: {
'*.css': { loader: 'systemjs-plugin-css' },
'*.vue': { loader: "../plugin-vue/index.js" }
}
});
})(this);