行操作
行操作是默认启用的,并且是在集算表的行头上。
有一些内置的行操作可以被添加。
名称
描述
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 = 'hide remove/save/reset'
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 = 'show remove/save/reset'
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 name="spreadjs culture" content="zh-cn" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css"
href="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/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$/zh/purejs/node_modules/@grapecity-software/spread-sheets/dist/gc.spread.sheets.all.min.js"
type="text/javascript"></script>
<script
src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-tablesheet/dist/gc.spread.sheets.tablesheet.min.js"
type="text/javascript"></script>
<script
src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-resources-zh/dist/gc.spread.sheets.resources.zh.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>Row Action</legend>
<div class="field-line">
<input type="button" id="change-option" value="hide remove/save/reset">
</div>
</fieldset>
<fieldset>
<legend>New Row</legend>
<div class="field-line">
<span>visible: </span><input type="checkbox" checked="checked" id="show-button" />
</div>
</fieldset>
</div>
</div>
</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;
}