Spread 수준 및 시트 수준 이벤트에 모두 바인딩할 수 있습니다. bind를 사용하여 이벤트를 바인딩하고 unbind를 사용하여 이벤트를 바인딩 해제할 수 있습니다. unbindAll을 사용하여 모든 이벤트를 바인딩 해제할 수 있습니다. jQuery의 바인딩 및 바인딩 해제 기능과 마찬가지로 Spread의 바인딩 및 바인딩 해제 기능을 유사한 방식으로 처리할 수 있습니다. 예:
Spread 또는 시트에서 이벤트를 트리거하지 않으려면 suspendEvent를 사용합니다. resumeEvent를 사용하여 트리거 이벤트를 다시 시작합니다. 예:
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(_getElementById("ss"), { sheetCount: 3 });
initSpread(spread);
};
function initSpread(spread) {
var spreadNS = GC.Spread.Sheets;
var sheet = spread.getActiveSheet();
spread.bind(spreadNS.Events.ActiveSheetChanged, function (e, args) {
_getElementById("showSpreadEvents").value=
'SpreadEvent: ' + GC.Spread.Sheets.Events.ActiveSheetChanged + ' event called' + '\n' +
'oldSheetName: ' + args.oldSheet.name() + '\n' +
'newSheetName: ' + args.newSheet.name();
});
spread.bind(spreadNS.Events.CellClick, function (e, args) {
var sheetArea = args.sheetArea === 0 ? 'sheetCorner' : args.sheetArea === 1 ? 'columnHeader' : args.sheetArea === 2 ? 'rowHeader' : 'viewPort';
_getElementById("showSpreadEvents").value=
'SpreadEvent: ' + GC.Spread.Sheets.Events.CellClick + ' event called' + '\n' +
'sheetArea: ' + sheetArea + '\n' +
'row: ' + args.row + '\n' +
'col: ' + args.col;
});
spread.bind(spreadNS.Events.SelectionChanging, function (e, args) {
var selection = args.newSelections.pop();
var sheetArea = args.sheetArea === 0 ? 'sheetCorner' : args.sheetArea === 1 ? 'columnHeader' : args.sheetArea === 2 ? 'rowHeader' : 'viewPort';
_getElementById("showSpreadEvents").value=
'SpreadEvent: ' + GC.Spread.Sheets.Events.SelectionChanging + ' event called' + '\n' +
'sheetArea: ' + sheetArea + '\n' +
'row: ' + selection.row + '\n' +
'column: ' + selection.col + '\n' +
'rowCount: ' + selection.rowCount + '\n' +
'colCount: ' + selection.colCount;
});
spread.bind(spreadNS.Events.SelectionChanged, function (e, args) {
var selection = args.newSelections.pop();
if(selection.rowCount > 1 && selection.colCount > 1){
var sheetArea = args.sheetArea === 0 ? 'sheetCorner' : args.sheetArea === 1 ? 'columnHeader' : args.sheetArea === 2 ? 'rowHeader' : 'viewPort';
_getElementById("showSpreadEvents").value=
'SpreadEvent: ' + GC.Spread.Sheets.Events.SelectionChanged + ' event called' + '\n' +
'sheetArea: ' + sheetArea + '\n' +
'row: ' + selection.row + '\n' +
'column: ' + selection.col + '\n' +
'rowCount: ' + selection.rowCount + '\n' +
'colCount: ' + selection.colCount;
}});
spread.bind(spreadNS.Events.EditStarting, function (e, args) {
_getElementById("showSpreadEvents").value=
'SpreadEvent: ' + GC.Spread.Sheets.Events.EditStarting + ' event called' + '\n' +
'row: ' + args.row + '\n' +
'column: ' + args.col;
});
spread.bind(spreadNS.Events.EditEnded, function (e, args) {
_getElementById("showSpreadEvents").value=
'SpreadEvent: ' + GC.Spread.Sheets.Events.EditEnded + ' event called' + '\n' +
'row: ' + args.row + '\n' +
'column: ' + args.col + '\n' +
'text: ' + args.editingText;
});
};
function _getElementById(id){
return document.getElementById(id);
}
<!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$/spread/source/data/data.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="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 class="options-container">
<div class="option-row">
<label>Click the sheet tab to change the active sheet. Click the cell or select range to edit.</label>
</div>
<div class="option-row">
<textarea id="showSpreadEvents" cols="40" rows="8" style="width: 90%"></textarea>
</div>
</div>
</div>
</body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: calc(100% - 280px);
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 {
display: block;
margin-bottom: 6px;
}
input {
padding: 4px 6px;
}
input[type=button] {
margin-top: 6px;
display: block;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}