List

One of the cell drop-down controls in SpreadJS is list. This drop-down can be defined in JavaScript code with the style properties. This style can be applied to cells in the workbook, creating a list with the defined items in that cell. The different types of list drop-downs are shown in the spreadsheet below.

Dropdowns provides developer the ability to add a drop down menu with specific properties to cells in a workbook. These drop down menus don't require any extra code other than simply specifying which one to use for the drop down menu. SpreadJS now have 8 different kinds of dropdowns, this is List. Before opening the list, you need to set the options data in cell's style. You can use List dropdown like the following code : You also can customize the organizational form of list through passing different option. The list options interface like this: You can refer the above sample's code in app.js. Customize List You can customize the list items with a function returns the dom element and a callback function return the value when clicked. MultiSelect List You can set the list to multi-select by set the options to true. It will use comma as separator character if the valueType is default or string.
import * as React from 'react'; import * as ReactDOM from 'react-dom'; import GC from '@grapecity/spread-sheets'; import { SpreadSheets } from '@grapecity/spread-sheets-react'; import './styles.css'; const Component = React.Component; function _getElementById(id) { return document.getElementById(id); } 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; } class App extends Component { constructor(props) { super(props); this.spread = null; this.autoGenerateColumns = false; } render() { return (<div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => this.initSpread(spread)}> </SpreadSheets> </div> </div>); } 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,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYA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 '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(); } } ReactDOM.render(<App />, _getElementById('app'));
<!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$/en/react/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- SystemJS --> <script src="$DEMOROOT$/en/react/node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('$DEMOROOT$/en/lib/react/license.js').then(function () { System.import('./src/app'); }); </script> </head> <body> <div id="app"></div> </body> </html>
.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; } #app { height: 100%; }
(function (global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true, react: true }, meta: { '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { '@grapecity/spread-sheets': 'npm:@grapecity/spread-sheets/index.js', '@grapecity/spread-sheets-react': 'npm:@grapecity/spread-sheets-react/index.js', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js', 'react': 'npm:react/umd/react.production.min.js', 'react-dom': 'npm:react-dom/umd/react-dom.production.min.js', 'css': 'npm:systemjs-plugin-css/css.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: 'jsx' }, "node_modules": { defaultExtension: 'js' }, } }); })(this);