列表

列表是SpreadJS中下拉列表的一种,列表定义在样式中,用户通过列表可以更易选择列表项。

下拉菜单使开发人员能够向工作簿中的单元格添加具有特定属性的下拉菜单。 这些下拉菜单不需要任何额外的代码,只需指定要使用哪一种下拉菜单即可。 SpreadJS目前拥有8种下拉列表,当前介绍的是列表。 在打开列表之前,你需要在单元格样式中设置选项数据。 你可以参考以下代码使用列表: 你还可以通过传递不同的选项来自定义列表的组织形式。 列表选项的接口如下: 关于列表的组织形式,你可以参考app.js中的实例代码。 自定义列表 你可以通过一个自定义函数并返回一个DOM元素来定制列表项的外观,以及一个自定义函数返回一个数值来定制列表项被点击时提交的值。 多选列表 你可以设置multi-select属性为true来控制列表多选,如果valueType为默认值或是字符串,那么返回值将返回以逗号分隔的多选项字串。
<template> <div class="sample-tutorial"> <gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread"> </gc-spread-sheets> </div> </template> <script> import Vue from "vue"; import '@grapecity-software/spread-sheets-resources-zh'; GC.Spread.Common.CultureManager.culture("zh-cn"); import "@grapecity-software/spread-sheets-vue"; import GC from "@grapecity-software/spread-sheets"; function generateStandardColors() { return generateColors(10, 0, 65526); } function generateThemeColors() { return generateColors(10, 0, 16777215); } function colorClicked(event) { let target = event.target; if (target && target.classList.contains("custom-color-block")) { let color = target.style.backgroundColor; return color; } return null; } function generateColors(count, start, stop) { function pad(pad, str, padLeft) { if (typeof str === "undefined") { return pad; } if (padLeft) { return (pad + str).slice(-pad.length); } else { return (str + pad).substring(0, pad.length); } } let div = document.createElement("div"); div.style.width = "140px"; let step = (stop - start) / count | 0; for (let i = start, index = 0; i < stop && index < count; i += step, index++) { let item = document.createElement("div"); item.style.backgroundColor = `#${pad('000000', i.toString(16), true)}`; item.style.width = '12px'; item.style.height = '12px'; item.style.border = '1px solid #c3c3c3'; item.classList.add("custom-color-block"); div.appendChild(item); } return div; } let App = Vue.extend({ name: "app", data: function() { return { spread: null }; }, methods: { initSpread(spread) { spread.setSheetCount(2); let sheet = spread.getSheet(0); this.initSheet(sheet, false); sheet = spread.getSheet(1); sheet.name("multi-select list"); this.initSheet(sheet, true); spread.commandManager().execute({ cmd: "openList", row: 3, col: 4, sheetName: "Sheet1" }); }, initSheet(sheet, multiSelect) { sheet.suspendPaint(); // -------------------- Vertical text list --------------------- let verticalStyle = new GC.Spread.Sheets.Style(); verticalStyle.cellButtons = [{ imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openList", useButtonStyle: true, }]; verticalStyle.dropDowns = [{ type: GC.Spread.Sheets.DropDownType.list, option: { multiSelect: multiSelect, items: [{ text: 'item1', value: 'item1' }, { text: 'item2', value: 'item2' }, { text: 'item3', value: 'item3' }, { text: 'item4', value: 'item4' } ], } }]; sheet.setText(2, 1, "Vertical text list"); sheet.setStyle(3, 1, verticalStyle); // -------------------- Simple Icon list --------------------- let simpleIconListData = { multiSelect: multiSelect, items: [{ text: 'item1', value: 'item1', icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABWUlEQVQ4T42SrUsEQRjGf68YNIsIomBSsGpSg1XQqMWPaxbBDxTdTV7bOVQ4DXa/ihZBNBsULNdE0GK4YLh/4ILwyg5zy+7c7uGkeed53t++z8wKBUtD+vll2Mrd1CWikWeVvEMNOAZ2Pe1EDHu+vw2gAZoyPbv9bOtMDJmeTKEBt8Cib/agd2JYSjytjYaMonwmX1fu6aVk6yZHwHqiCWMS8RXXyQQasAxcp0wLwICr31HeUtFWxHDjA+LR4wjx+hHDoAaUrclQ1oBvYMTpG2I4zwL2GaKLujUoVamw4wFi2KHT56XCYwZg+wKegDmEKaAP5cE2CHGchotRE8Nk2yVawAFrCBf+W2dqpSQVLnMBbopTYLMAciaGrbRW9Ce+ANMe5FUMMz44HxAyjlIDelxDE2FCIj7+BbBRQlZRl1VYk4irvFi5E7SMGlB1/8F20cV2BHR8DSf+ATHpYBEJcyFZAAAAAElFTkSuQmCC" }, { text: 'item2', value: 'item2', icon: "data:image/png;base64,i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ATHpYBEJcyFZAAAAAElFTkSuQmCC" }, { text: 'item4', value: 'item4', icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABWUlEQVQ4T42SrUsEQRjGf68YNIsIomBSsGpSg1XQqMWPaxbBDxTdTV7bOVQ4DXa/ihZBNBsULNdE0GK4YLh/4ILwyg5zy+7c7uGkeed53t++z8wKBUtD+vll2Mrd1CWikWeVvEMNOAZ2Pe1EDHu+vw2gAZoyPbv9bOtMDJmeTKEBt8Cib/agd2JYSjytjYaMonwmX1fu6aVk6yZHwHqiCWMS8RXXyQQasAxcp0wLwICr31HeUtFWxHDjA+LR4wjx+hHDoAaUrclQ1oBvYMTpG2I4zwL2GaKLujUoVamw4wFi2KHT56XCYwZg+wKegDmEKaAP5cE2CHGchotRE8Nk2yVawAFrCBf+W2dqpSQVLnMBbopTYLMAciaGrbRW9Ce+ANMe5FUMMz44HxAyjlIDelxDE2FCIj7+BbBRQlZRl1VYk4irvFi5E7SMGlB1/8F20cV2BHR8DSf+ATHpYBEJcyFZAAAAAElFTkSuQmCC" } ] }; let simpleIconListStyle = new GC.Spread.Sheets.Style(); simpleIconListStyle.cellButtons = [{ imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openList", useButtonStyle: true, }]; simpleIconListStyle.dropDowns = [{ type: GC.Spread.Sheets.DropDownType.list, option: simpleIconListData }]; sheet.setText(2, 4, "Vertical text list"); sheet.setStyle(3, 4, simpleIconListStyle); // -------------------- Vertical group list --------------------- let groupListData = { multiSelect: multiSelect, items: [{ text: 'group 1', layout: { displayAs: GC.Spread.Sheets.LayoutDisplayAs.inline }, items: [{ text: 'item1', value: 'item1' }, { text: 'item2', value: 'item2' } ], }, { text: 'group 2', layout: { displayAs: GC.Spread.Sheets.LayoutDisplayAs.inline }, items: [{ text: 'item3', value: 'item3' }, { text: 'item4', value: 'item4' } ] } ] }; let groupListStyle = new GC.Spread.Sheets.Style(); groupListStyle.cellButtons = [{ imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openList", useButtonStyle: true, }]; groupListStyle.dropDowns = [{ type: GC.Spread.Sheets.DropDownType.list, option: groupListData }]; sheet.setText(2, 8, "Vertical group list"); sheet.setStyle(3, 8, groupListStyle); // -------------------- Vertical cascade group list --------------------- let cascadeListData = { multiSelect: multiSelect, items: [{ text: 'item1', value: 'item1', layout: { displayAs: GC.Spread.Sheets.LayoutDisplayAs.popup }, items: [{ text: 'sub-item1', value: 'sub-item1' }, { text: 'sub-item2', value: 'sub-item2' } ] }, { text: 'item2', value: 'item2', }, { text: 'item3', value: 'item3', }, { text: 'item4', value: 'item4', } ] }; let verticalCascadeListStyle = new GC.Spread.Sheets.Style(); verticalCascadeListStyle.cellButtons = [{ imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openList", useButtonStyle: true, }]; verticalCascadeListStyle.dropDowns = [{ type: GC.Spread.Sheets.DropDownType.list, option: cascadeListData }]; sheet.setText(2, 12, "Vertical cascade group list"); sheet.setStyle(3, 12, verticalCascadeListStyle); // -------------------- Group cascade list --------------------- let groupCascadeListData = { multiSelect: multiSelect, items: [{ text: 'group 1', layout: { displayAs: GC.Spread.Sheets.LayoutDisplayAs.inline }, items: [{ text: 'item1', value: 'item1', layout: { displayAs: GC.Spread.Sheets.LayoutDisplayAs.popup }, items: [{ text: 'sub-item1', value: 'sub-item1' }, { text: 'sub-item2', value: 'sub-item2' } ] }, { text: 'item2', value: 'item2', } ] }, { text: 'group 2', layout: { displayAs: GC.Spread.Sheets.LayoutDisplayAs.inline }, items: [{ text: 'item3', value: 'item3', }, { text: 'item4', value: 'item4', } ] } ] }; let groupCascadeListStyle = new GC.Spread.Sheets.Style(); groupCascadeListStyle.cellButtons = [{ imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openList", useButtonStyle: true, }]; groupCascadeListStyle.dropDowns = [{ type: GC.Spread.Sheets.DropDownType.list, option: groupCascadeListData }]; sheet.setText(11, 1, "Group cascade list"); sheet.setStyle(12, 1, groupCascadeListStyle); // -------------------- Tree list --------------------- let treeListData = { multiSelect: multiSelect, items: [{ text: 'group 1', layout: { displayAs: GC.Spread.Sheets.LayoutDisplayAs.tree, collapsible: true }, items: [{ text: 'sub group 1-1', layout: { displayAs: GC.Spread.Sheets.LayoutDisplayAs.tree, collapsible: true }, items: [{ text: 'sub group item1', value: 'subGroupItem1' }, { text: 'sub group item2', value: 'subGroupItem2' } ] }, { text: 'sub group 1-2', value: 'subGroup12' } ], }, { text: 'group 2', layout: { displayAs: GC.Spread.Sheets.LayoutDisplayAs.tree }, items: [{ text: 'sub group 2-1', layout: { displayAs: GC.Spread.Sheets.LayoutDisplayAs.tree }, items: [{ text: 'sub group item3', value: 'subGroupItem3' }, { text: 'sub group item4', value: 'subGroupItem5' } ] }, { text: 'sub group 2-2', value: 'subGroup22' } ], }, ] }; let treeListStyle = new GC.Spread.Sheets.Style(); treeListStyle.cellButtons = [{ imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openList", useButtonStyle: true, }]; treeListStyle.dropDowns = [{ type: GC.Spread.Sheets.DropDownType.list, option: treeListData }]; sheet.setText(11, 4, "Vertical tree list"); sheet.setStyle(12, 4, treeListStyle); // -------------------- Horizontal group list --------------------- let horizontalGroupListData = { multiSelect: multiSelect, layout: { direction: GC.Spread.Sheets.LayoutDirection.horizontal }, items: [{ layout: { displayAs: GC.Spread.Sheets.LayoutDisplayAs.inline, direction: GC.Spread.Sheets.LayoutDirection.horizontal }, text: 'group 1', items: [{ text: 'item1', value: 'item1' }, { text: 'item2', value: 'item2' } ], }, { text: 'group 2', layout: { displayAs: GC.Spread.Sheets.LayoutDisplayAs.inline }, items: [{ text: 'item3', value: 'item3' }, { text: 'item4', value: 'item4' } ] } ] }; let horizontalGroupListStyle = new GC.Spread.Sheets.Style(); horizontalGroupListStyle.cellButtons = [{ imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openList", useButtonStyle: true, }]; horizontalGroupListStyle.dropDowns = [{ type: GC.Spread.Sheets.DropDownType.list, option: horizontalGroupListData }]; sheet.setText(11, 8, "Vertical tree list"); sheet.setStyle(12, 8, horizontalGroupListStyle); // -------------------- Custom list --------------------- // This part just shows how to custom a list. (not a real color selector) let colorListData = { multiSelect: multiSelect, onItemSelected: colorClicked, items: [{ text: 'Theme Colors', layout: { direction: GC.Spread.Sheets.LayoutDirection.horizontal, displayAs: GC.Spread.Sheets.LayoutDisplayAs.inline }, items: generateThemeColors }, { text: 'Standard Colors', layout: { direction: GC.Spread.Sheets.LayoutDirection.horizontal, displayAs: GC.Spread.Sheets.LayoutDisplayAs.inline }, items: generateStandardColors }, { text: 'No Color', value: 'nocolor' }, { text: 'More Colors...', value: 'morecolors', icon: 'more-color-icon' } ] }; let customStyle = new GC.Spread.Sheets.Style(); customStyle.cellButtons = [{ imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openList", useButtonStyle: true, }]; customStyle.dropDowns = [{ type: GC.Spread.Sheets.DropDownType.list, option: colorListData }]; sheet.setText(11, 12, "Custom list"); sheet.setStyle(12, 12, customStyle); sheet.resumePaint(); } } }); new Vue({ render: h => h(App) }).$mount("#app"); </script> <style> .sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: 100%; height: 100%; overflow: hidden; float: left; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } </style>
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/zh/vue/node_modules/@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- SystemJS --> <script src="$DEMOROOT$/zh/vue/node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); System.import('$DEMOROOT$/zh/lib/vue/license.js'); </script> </head> <body> <div id="app"></div> </body> </html>
(function(global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, meta: { '*.css': { loader: 'css' }, '*.vue': { loader: 'vue-loader' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { '@grapecity-software/spread-sheets': 'npm:@grapecity-software/spread-sheets/index.js', '@grapecity-software/spread-sheets-resources-zh': 'npm:@grapecity-software/spread-sheets-resources-zh/index.js', '@grapecity-software/spread-sheets-vue': 'npm:@grapecity-software/spread-sheets-vue/index.js', '@grapecity-software/jsob-test-dependency-package/react-components': 'npm:@grapecity-software/jsob-test-dependency-package/react-components/index.js', 'jszip': 'npm:jszip/dist/jszip.js', 'css': 'npm:systemjs-plugin-css/css.js', 'vue': 'npm:vue/dist/vue.min.js', 'vue-loader': 'npm:systemjs-vue-browser/index.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' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'js' }, rxjs: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' } } }); })(this);