概要と基本的な使い方

行アクションは、行ヘッダーに付加された特別な列であり、データの保存、削除、リセットなどを、UIを使って簡単に行えるようにするものです。

「新しい行」は、テーブルシートの下部にある特別な行で、データが追加されると自動的に新しい行を挿入します。

行アクション 行アクションはデフォルトで有効になっており、テーブルシートの行ヘッダーにあります。 いくつかの定義済みの行アクションを使用できます: 名前 説明 pinRow 行をピン留めする dirtyStatus データの変更を行に表示する warningInfo 警告情報を行に表示する removeRow 行を削除する saveRow 行のデータの変更を保存する resetRow 行のデータの変更をリセットする 削除、保存、リセットアクションの追加: 新しい行 新しい行はデフォルトで有効になっており、テーブルシートの一番下に表示されます。次のコマンドで非表示または表示できます:
<template> <div class="sample-tutorial"> <gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="init"> </gc-spread-sheets> <div id="options-container" class="options-container"> <fieldset> <legend>行アクション</legend> <div class="field-line"> <input type="button" id="change-option" v-bind:value="toggleRowActionTitleRef" @click="toggleRowActions()"> </div> </fieldset> <fieldset> <legend>新しい行</legend> <div class="field-line"> <span>表示:</span><input type="checkbox" v-model="newRowVisibleRef" id="show-button" @change="toggleNewRow()" /> </div> </fieldset> </div> </div> </template> <script setup> import GC from "@mescius/spread-sheets"; import { ref } from "vue"; import "@mescius/spread-sheets-tablesheet"; import '@mescius/spread-sheets-resources-ja'; GC.Spread.Common.CultureManager.culture("ja-jp"); import "@mescius/spread-sheets-vue"; const spreadRef = ref(null); const tablesheetRef = ref(null); const toggleRowActionTitleRef = ref('削除/保存/リセットを隠す'); const newRowVisibleRef = ref(true); function init(spread) { initSpread(spread); } function initSpread(spread) { spreadRef.value = 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 var 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); tablesheetRef.value = sheet; //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 toggleNewRow() { tablesheetRef.value.options.allowAddNew = newRowVisibleRef.value; } function toggleRowActions() { let sheet = tablesheetRef.value; let options = sheet.rowActionOptions(); if (options.length === 1) { toggleRowActionTitleRef.value = '削除/保存/リセットを隠す' var rowActions = GC.Spread.Sheets.TableSheet.BuiltInRowActions; options.push( setTooltip(rowActions.removeRow, 'Remove'), setTooltip(rowActions.saveRow, 'Save'), setTooltip(rowActions.resetRow, 'Reset'), ); } else { toggleRowActionTitleRef.value = '削除/保存/リセットを表示' options.splice(1, options.length); } sheet.rowActionOptions(options); } function setTooltip(options, tooltip) { options.tooltip = tooltip; return options; } </script> <style scoped> #app { height: 100%; } 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 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; } .field-inline { display: inline-block; vertical-align: middle; } fieldset label.field-inline { width: 100px; } fieldset input.field-inline { width: calc(100% - 100px - 12px); } .required { color: red; font-weight: bold; } #fields { display: none; } #fields.show { display: block; } </style>
<!DOCTYPE html> <html lang="en" 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$/ja/vue3/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/ja/vue3/node_modules/systemjs/dist/system.src.js"></script> <script src="$DEMOROOT$/spread/source/data/employees.js" type="text/javascript"></script> <script src="./systemjs.config.js"></script> <script src="./compiler.js" type="module"></script> <script> var System = SystemJS; System.import("./src/app.js"); System.import('$DEMOROOT$/ja/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-ja': 'npm:@mescius/spread-sheets-resources-ja/index.js', '@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/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);