下拉菜单使开发人员能够向工作簿中的单元格添加具有特定属性的下拉菜单。 这些下拉菜单不需要任何额外的代码,只需指定要使用哪一种下拉菜单即可。
SpreadJS目前拥有8种下拉列表,当前介绍的是时间选择器下拉列表。
你可以使用时间选择器下拉列表,如以下代码所示:
还有一些用于自定义时间选择器的选项:
max: ITimePickerValue : 时间选择器可显示的最大值,这个值需要时、分、秒等属性。
min: ITimePickerValue : 时间选择器可以显示的最小值,这个值需要时、分、秒等属性。
setp: ITimePickerValue : 时间选择器的步长。
formatString: string : 指定时间选择器显示的时间格式。
height: number : 指定时间选择器容器的高度,默认是300。
var spreadNS = GC.Spread.Sheets;
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
initSpread(spread);
};
function createPickerStyle(option) {
var timePickerStyle = new GC.Spread.Sheets.Style();
timePickerStyle.cellButtons = [
{
imageType: GC.Spread.Sheets.ButtonImageType.dropdown,
command: "openTimePicker",
useButtonStyle: true,
}
];
timePickerStyle.dropDowns = [
{
type: GC.Spread.Sheets.DropDownType.timePicker,
option: option
}
];
return timePickerStyle;
}
function initSpread(spread) {
var sheet = spread.getSheet(0);
sheet.suspendPaint();
sheet.setText(1, 3, "Time Picker");
sheet.setStyle(2, 3, createPickerStyle({
min: { hour: 8 },
max: { hour: 19 },
step: { minute: 30 },
formatString: "h:mm AM/PM",
}));
sheet.setText(1, 7, "Time Picker");
sheet.setStyle(2, 7, createPickerStyle({
min: { hour: 5 },
max: { hour: 20 },
step: { minute: 30 },
formatString: "h:mm:ss",
height: 350
}));
sheet.resumePaint();
spread.commandManager().execute({cmd:"openTimePicker",row:2,col:3,sheetName:"Sheet1"});
}
<!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">
<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-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" style="width:100%; height: 100%"></div>
</div>
</body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}