日期时间选择器

日期时间选择器是SpreadJS中的一种下拉菜单,日期时间选择器下拉菜单定义在样式中,通过日期时间选择器用户可以方便地选择日期时间。

下拉菜单使开发人员能够向工作簿中的单元格添加具有特定属性的下拉菜单。 这些下拉菜单不需要任何额外的代码,只需指定要使用哪一种下拉菜单即可。 SpreadJS目前拥有8种下拉列表,当前介绍的是日期时间选择器下拉列表。 你可以使用日期时间选择器下拉列表,如以下代码所示: 日期时间选择器下拉列表有以下选项: showTime: boolean : 指定日历是否需要显示时间部分。 calendarPage: CalendarPage : 指定日历默认显示的内容,这个值可以是年,月,日,例如: calendarPage: GC.Spread.Sheets.CalendarPage.year. startDay: CalendarStartDay : 指定一周的起始日期,通常一周的起始日期是周一或者周日,用户可以通过这个选项设置一周内的任一天为起始日期,例如:startDay: GC.Spread.Sheets.CalendarStartDay.monday.
var spreadNS = GC.Spread.Sheets; window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss")); initSpread(spread); }; function initSpread(spread) { var sheet = spread.getSheet(0); sheet.suspendPaint(); // -------------------- Date Time Picker : showTime true --------------------- var showTimeStyle = new GC.Spread.Sheets.Style(); showTimeStyle.cellButtons = [ { imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openDateTimePicker", useButtonStyle: true, } ]; showTimeStyle.dropDowns = [ { type: GC.Spread.Sheets.DropDownType.dateTimePicker, option: { showTime: true } } ]; sheet.setText(1, 2, "Date Time Picker (showTime: true)"); sheet.setStyle(2, 5, showTimeStyle); // -------------------- Date Time Picker : showTime False --------------------- var notShowTimestyle = new GC.Spread.Sheets.Style(); notShowTimestyle.cellButtons = [ { imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openDateTimePicker", useButtonStyle: true, } ]; notShowTimestyle.dropDowns = [ { type: GC.Spread.Sheets.DropDownType.dateTimePicker, option: { showTime: false } } ]; sheet.setText(20, 2, "Date Time Picker (showTime: false)"); sheet.setStyle(21, 5, notShowTimestyle); // -------------------- Date Time Picker : CalendarPage - Year --------------------- var calendarYearStyle = new GC.Spread.Sheets.Style(); calendarYearStyle.cellButtons = [ { imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openDateTimePicker", useButtonStyle: true, } ]; calendarYearStyle.dropDowns = [ { type: GC.Spread.Sheets.DropDownType.dateTimePicker, option: { showTime: true, calendarPage: GC.Spread.Sheets.CalendarPage.year, } } ]; sheet.setText(20, 8, "Date Time picker (calendarPage - Year)"); sheet.setStyle(21, 11, calendarYearStyle); // -------------------- Date Time Picker : CalendarPage - Month --------------------- var calendarMonthStyle = new GC.Spread.Sheets.Style(); calendarMonthStyle.cellButtons = [ { imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openDateTimePicker", useButtonStyle: true, } ]; calendarMonthStyle.dropDowns = [ { type: GC.Spread.Sheets.DropDownType.dateTimePicker, option: { showTime: true, calendarPage: GC.Spread.Sheets.CalendarPage.month, } } ]; sheet.setText(1, 8, "Date Time picker (calendarPage - Month)"); sheet.setStyle(2, 11, calendarMonthStyle); sheet.resumePaint(); spread.commandManager().execute({cmd:"openDateTimePicker",row:2,col:5,sheetName:"Sheet1"}); // spread.commandManager().execute({cmd:"openDateTimePicker",row:2,col:11,sheetName:"Sheet1"}); // spread.commandManager().execute({cmd:"openDateTimePicker",row:21,col:11,sheetName:"Sheet1"}); // spread.commandManager().execute({cmd:"openDateTimePicker",row:21,col:5,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/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity/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; }