行アクション
行アクションはデフォルトで有効になっており、テーブルシートの行ヘッダーにあります。
いくつかの定義済みの行アクションを使用できます:
名前
説明
pinRow
行をピン留めする
dirtyStatus
データの変更を行に表示する
warningInfo
警告情報を行に表示する
removeRow
行を削除する
saveRow
行のデータの変更を保存する
resetRow
行のデータの変更をリセットする
削除、保存、リセットアクションの追加:
新しい行
新しい行はデフォルトで有効になっており、テーブルシートの一番下に表示されます。次のコマンドで非表示または表示できます:
/*REPLACE_MARKER*/
/*DO NOT DELETE THESE COMMENTS*/
var sheet;
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 0 });
//register self-defined row action command
initSpread(spread);
bindEvents();
};
function initSpread(spread) {
spread.suspendPaint();
spread.clearSheets();
spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader;
//init a data manager
var dataManager = spread.dataManager();
var myTable = dataManager.addTable("myTable", {
data:employees
});
//init a table sheet
sheet = spread.addSheetTab(0, "MyTableSheet", GC.Spread.Sheets.SheetType.tableSheet);
var rowActions = GC.Spread.Sheets.TableSheet.BuiltInRowActions;
let options = sheet.rowActionOptions();
options.push(
rowActions.removeRow,
rowActions.saveRow,
rowActions.resetRow,
);
sheet.rowActionOptions(options);
//bind a view to the table sheet
myTable.fetch().then(function () {
var view = myTable.addView("myView", [
{ value: "Id", width: 50, caption: "ID" },
{ value: "FirstName", width: 100, caption: "First Name" },
{ value: "LastName", width: 100, caption: "Last Name" },
{ value: "HomePhone", width: 150, caption: "Phone" },
{ value: "PhotoPath", width: 150, caption: "Attachment" },
{ value: "Notes", width: 400, caption: "Comments" },
]);
sheet.setDataView(view);
});
spread.resumePaint();
}
function bindEvents() {
var changeOptionButton = document.getElementById('change-option');
changeOptionButton.addEventListener('click', function () {
let options = sheet.rowActionOptions();
if (options.length === 1) {
changeOptionButton.value = '削除/保存/リセットを隠す'
var rowActions = GC.Spread.Sheets.TableSheet.BuiltInRowActions;
options.push(setTooltip(rowActions.removeRow, 'Remove'));
options.push(setTooltip(rowActions.saveRow, 'Save'));
options.push(setTooltip(rowActions.resetRow, 'Reset'));
} else {
changeOptionButton.value = '削除/保存/リセットを表示'
options.splice(1, options.length);
}
sheet.rowActionOptions(options);
});
var showButton = document.getElementById('show-button');
showButton.addEventListener('change', function () {
sheet.options.allowAddNew = showButton.checked;
});
}
function setTooltip(options, tooltip) {
options.tooltip = tooltip;
return options;
}
function getProperty(domId, prop) {
return document.getElementById(domId)[prop];
}
function setProperty(domId, prop, value) {
document.getElementById(domId)[prop] = value;
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<meta name="spreadjs culture" content="ja-jp" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.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$/ja/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-tablesheet/dist/gc.spread.sheets.tablesheet.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-resources-ja/dist/gc.spread.sheets.resources.ja.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/data/employees.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 id="options-container" class="options-container">
<fieldset>
<legend>行アクション</legend>
<div class="field-line">
<input type="button" id="change-option" value="削除/保存/リセットを隠す">
</div>
</fieldset>
<fieldset>
<legend>新しい行</legend>
<div class="field-line">
<span>表示:</span><input type="checkbox" checked="checked" id="show-button" />
</div>
</fieldset>
</div>
</div>
</body>
</html>
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
fieldset {
padding: 6px;
margin: 0;
margin-top: 10px;
}
.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;
}
fieldset span,
fieldset input,
fieldset select {
display: inline-block;
text-align: left;
}
fieldset span {
width: 50px;
}
fieldset input[type=text] {
width: calc(100% - 58px);
}
fieldset input[type=button] {
width: 100%;
text-align: center;
}
fieldset select {
width: calc(100% - 50px);
}
.field-line {
margin-top: 4px;
}