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 9 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 { Component, NgModule, enableProdMode } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { SpreadSheetsModule } from '@grapecity/spread-sheets-angular';
import GC from '@grapecity/spread-sheets';
import './styles.css';
@Component({
selector: 'app-component',
templateUrl: 'src/app.component.html'
})
export class AppComponent {
hostStyle = {
width: '100%',
height: '100%',
overflow: 'hidden',
float: 'left'
};
initSpread($event: any) {
let spread = $event.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: GC.Spread.Sheets.WorkSheet, multiSelect: boolean) {
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,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABWUlEQVQ4T42SrUsEQRjGf68YNIsIomBSsGpSg1XQqMWPaxbBDxTdTV7bOVQ4DXa/ihZBNBsULNdE0GK4YLh/4ILwyg5zy+7c7uGkeed53t++z8wKBUtD+vll2Mrd1CWikWeVvEMNOAZ2Pe1EDHu+vw2gAZoyPbv9bOtMDJmeTKEBt8Cib/agd2JYSjytjYaMonwmX1fu6aVk6yZHwHqiCWMS8RXXyQQasAxcp0wLwICr31HeUtFWxHDjA+LR4wjx+hHDoAaUrclQ1oBvYMTpG2I4zwL2GaKLujUoVamw4wFi2KHT56XCYwZg+wKegDmEKaAP5cE2CHGchotRE8Nk2yVawAFrCBf+W2dqpSQVLnMBbopTYLMAciaGrbRW9Ce+ANMe5FUMMz44HxAyjlIDelxDE2FCIj7+BbBRQlZRl1VYk4irvFi5E7SMGlB1/8F20cV2BHR8DSf+ATHpYBEJcyFZAAAAAElFTkSuQmCC"
},
{
text: 'item3',
value: 'item3',
icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABWUlEQVQ4T42SrUsEQRjGf68YNIsIomBSsGpSg1XQqMWPaxbBDxTdTV7bOVQ4DXa/ihZBNBsULNdE0GK4YLh/4ILwyg5zy+7c7uGkeed53t++z8wKBUtD+vll2Mrd1CWikWeVvEMNOAZ2Pe1EDHu+vw2gAZoyPbv9bOtMDJmeTKEBt8Cib/agd2JYSjytjYaMonwmX1fu6aVk6yZHwHqiCWMS8RXXyQQasAxcp0wLwICr31HeUtFWxHDjA+LR4wjx+hHDoAaUrclQ1oBvYMTpG2I4zwL2GaKLujUoVamw4wFi2KHT56XCYwZg+wKegDmEKaAP5cE2CHGchotRE8Nk2yVawAFrCBf+W2dqpSQVLnMBbopTYLMAciaGrbRW9Ce+ANMe5FUMMz44HxAyjlIDelxDE2FCIj7+BbBRQlZRl1VYk4irvFi5E7SMGlB1/8F20cV2BHR8DSf+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);
// spread.commandManager().execute({cmd:"openList",row:12,col:12,sheetName:"List"});
sheet.resumePaint();
// spread.commandManager().execute({cmd:"openList",row:3,col:1,sheetName:"Sheet1"});
// spread.commandManager().execute({cmd:"openList",row:3,col:8,sheetName:"Sheet1"});
// spread.commandManager().execute({cmd:"openList",row:3,col:12,sheetName:"Sheet1"});
// spread.commandManager().execute({cmd:"openList",row:12,col:1,sheetName:"Sheet1"});
// spread.commandManager().execute({cmd:"openList",row:12,col:4,sheetName:"Sheet1"});
// spread.commandManager().execute({cmd:"openList",row:12,col:8,sheetName:"Sheet1"});
}
}
function generateThemeColors() {
return generateColors(10, 0, 16777215)
}
function generateStandardColors() {
return generateColors(10, 0, 65526)
}
function colorClicked(event: Event) {
let target = <HTMLElement>event.target;
if (target && target.classList.contains("custom-color-block")) {
let color = target.style.backgroundColor;
return color;
}
return null;
}
function pad(pad: string, str: string, padLeft: boolean) {
if (typeof str === "undefined") {
return pad;
}
if (padLeft) {
return (pad + str).slice(-pad.length);
} else {
return (str + pad).substring(0, pad.length);
}
}
function generateColors(count: number, start: number, stop: number) {
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;
}
@NgModule({
imports: [BrowserModule, SpreadSheetsModule],
declarations: [AppComponent],
exports: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
enableProdMode();
// Bootstrap application with hash style navigation and global services.
platformBrowserDynamic().bootstrapModule(AppModule);
<!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/angular/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<!-- Polyfills -->
<script src="$DEMOROOT$/en/angular/node_modules/core-js/client/shim.min.js"></script>
<script src="$DEMOROOT$/en/angular/node_modules/zone.js/dist/zone.min.js"></script>
<!-- SystemJS -->
<script src="$DEMOROOT$/en/angular/node_modules/systemjs/dist/system.js"></script>
<script src="systemjs.config.js"></script>
<script>
// workaround to load 'rxjs/operators' from the rxjs bundle
System.import('rxjs').then(function (m) {
System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators));
System.import('$DEMOROOT$/en/lib/angular/license.ts');
System.import('./src/app.component');
});
</script>
</head>
<body>
<app-component></app-component>
</body>
</html>
<div class="sample-tutorial">
<gc-spread-sheets [hostStyle]="hostStyle" (workbookInitialized)="initSpread($event)">
</gc-spread-sheets>
</div>
.sample-tutorial {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
(function (global) {
System.config({
transpiler: 'ts',
typescriptOptions: {
tsconfig: true
},
meta: {
'typescript': {
"exports": "ts"
},
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'core-js': 'npm:core-js/client/shim.min.js',
'zone': 'npm:zone.js/dist/zone.min.js',
'rxjs': 'npm:rxjs/bundles/rxjs.umd.min.js',
'@angular/core': 'npm:@angular/core/bundles/core.umd.min.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.min.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.min.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.min.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.min.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.min.js',
'@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.min.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.min.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.min.js',
'jszip': 'npm:jszip/dist/jszip.min.js',
'typescript': 'npm:typescript/lib/typescript.js',
'ts': 'npm:plugin-typescript/lib/plugin.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',
'@grapecity/spread-sheets': 'npm:@grapecity/spread-sheets/index.js',
'@grapecity/spread-sheets-angular': 'npm:@grapecity/spread-sheets-angular/bundles/grapecity-spread-sheets-angular.umd.js',
'@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'ts'
},
rxjs: {
defaultExtension: 'js'
},
"node_modules": {
defaultExtension: 'js'
},
}
});
})(this);