自定义

用户可以通过传递带有iconsiconSelectortooltipshortcutKeycommand的自定义选项来定制行动作。

你可以使用sheet.rowActionOptions()方法获得行操作选项。 你可以使用sheet.rowActionOptions(rowActionOptions)来定制它,其中rowActionOptions包括以下内容。 行为 类型 描述 name string 该选项的名称 icons (string | GC.Spread.Sheets.ButtonImageType)[] 一系列的图标表示不同的状态 iconSelector (item: any, index: number) => number | boolean 根据不同的状态选择一个图标 tooltip string 该行命令的工具提示 command string 点击该行命令时的命令名称 shortcutKey GC.Spread.Sheets.TableSheet.IShortcutKey 该行命令的命令的快捷键 添加一个有评论的行命令可以用以下代码完成。 添加一个行命令,命令如下。 对默认的第一行指定一个命令,如下所示:
/*REPLACE_MARKER*/ /*DO NOT DELETE THESE COMMENTS*/ var tableName = "Employee"; var baseApiUrl = getBaseApiUrl(); var apiUrl = baseApiUrl + "/" + tableName; var sheet; var ShowComment = "ShowComment"; var CheckRow = "CheckRow"; var checkMap = {}; window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 0 }); //register self-defined row action command registerCommands(); initSpread(spread); }; 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", { remote: { read: { url: apiUrl }, update: { url: apiUrl, method: 'PUT' }, create: { url: apiUrl }, delete: { url: apiUrl } }, autoSync: true }); //init a table sheet sheet = spread.addSheetTab(0, "MyTableSheet", GC.Spread.Sheets.SheetType.tableSheet); var options = sheet.rowActionOptions(); // Specify a command to the default first row action var defaultFirstRowAction = options[0]; defaultFirstRowAction.command = GC.Spread.Sheets.TableSheet.BuiltInRowActions.pinRow.command; //add a action of check/uncheck options.push({ name: 'check', icons: ["data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iMTIiIHZpZXdCb3g9IjAgMCAxMiAxMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjEyIiBoZWlnaHQ9IjEyIiBmaWxsPSJ0cmFuc3BhcmVudCIvPgo8cmVjdCB3aWR0aD0iMTIiIGhlaWdodD0iMTIiIGZpbGw9InRyYW5zcGFyZW50Ii8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMTIgMEgwVjEySDEyVjBaTTEgMTFWMUgxMVYxMUgxWiIgZmlsbD0iIzY2NjY2NiIvPgo8L3N2Zz4K", "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iMTIiIHZpZXdCb3g9IjAgMCAxMiAxMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjEyIiBoZWlnaHQ9IjEyIiBmaWxsPSJ0cmFuc3BhcmVudCIvPgo8cmVjdCB3aWR0aD0iMTIiIGhlaWdodD0iMTIiIGZpbGw9InRyYW5zcGFyZW50Ii8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMTIgMEgwVjEySDEyVjBaTTEgMTFWMUgxMVYxMUgxWiIgZmlsbD0iIzY2NjY2NiIvPgo8cGF0aCBkPSJNNS4yNSA5TDIgNS42MTI5TDMuMDA3MTQgNC41NjMyOEw1LjI1IDYuODkzM0w4Ljk4NTcxIDNMMTAgNC4wNDk2M0w1LjI1IDlINS4yNVoiIGZpbGw9IiM2NjY2NjYiLz4KPC9zdmc+Cg=="], tooltip: "Check/Uncheck", iconSelector: function (item) { return !!checkMap[item.Id]; }, command: CheckRow }); //show the comment flag if the data has a comment options.push({ name: 'comment', icons: ["./image/comment.png"], tooltip: "Show the comment", iconSelector: function (item) { return item.Notes ? item.Notes.length > 0 : false; }, shortcutKey: { key: 65 /* A */, ctrl: true, alt: true }, command: ShowComment }); //show the attachment flag if the data has a attachment options.push({ name: 'attachment', icons: ["./image/attachment.png"], tooltip: "Attachment", iconSelector: function (item) { return item.PhotoPath ? item.PhotoPath.length > 0 : false; } }); 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 registerCommands() { var Commands = GC.Spread.Sheets.Commands; Commands[ShowComment] = { canUndo: false, execute: function (context, options) { alert(options.item.Notes); return true; } }; Commands[CheckRow] = { canUndo: false, execute: function (context, options) { var id = options.item.Id; checkMap[id] = !checkMap[id]; return true; } }; } function getProperty(domId, prop) { return document.getElementById(domId)[prop]; } function setProperty(domId, prop, value) { document.getElementById(domId)[prop] = value; } function getBaseApiUrl() { return window.location.href.match(/http.+spreadjs\/SpreadJSTutorial\//)[0] + 'server/api'; }
<!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="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> </html>
body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } .sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: 100%; height: 100%; overflow: hidden; float: left; }