滑动条

滑动条是SpreadJS中的一种下拉菜单,它定义在单元格的样式中,可以令用户更易选择数据。

下拉菜单使开发人员能够向工作簿中的单元格添加具有特定属性的下拉菜单。 这些下拉菜单不需要任何额外的代码,只需指定要使用哪一种下拉菜单即可。 SpreadJS目前拥有9种下拉列表,当前介绍的是滑动条。 你可以使用滑动条,如以下代码所示: 还有一些用于自定义滑动条的选项: scaleVisible: boolean : 指定拇指是否只能拖动刻度线,默认值为false。 max: number : 滑动条可以滑动的最大值,默认是100。 min: number : 滑动条可以滑动的最小值,默认是0。 step: number : 滑动条调整值得步长。 必须大于0,并且可以被最大值最小值之差整除。 当标记不为null时,step可以为null, 默认值为1。 tooltipVisible: boolean : 如果设置为true,则工具提示将始终显示,反之,即使拖动或者悬停也不会显示。默认值是false。 width: number : 当方向为水平方向时,指定滑动条的宽度,默认值为350。 height: number : 当方向为垂直时,指定滑动条的高度,默认值为350。 direction: "horizontal" | "vertical" : 指定滑动条的方向,默认为水平方向。 marks: number[] : 滑动条的刻度标记,其中包括值和标签。 formatString: string : 指定显示的格式,用于工具提示或者标记。 showNumberRange: boolean:指定滑动条是否显示为选择数值范围模式,默认值为false。
var spreadNS = GC.Spread.Sheets; window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss")); initSpread(spread); }; function createSliderStyle(option) { let sliderStyle = new GC.Spread.Sheets.Style(); sliderStyle.cellButtons = [{ imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openSlider", useButtonStyle: true }]; sliderStyle.dropDowns = [{ type: GC.Spread.Sheets.DropDownType.slider, option: option }]; return sliderStyle } function initSpread(spread) { var sheet = spread.getSheet(0); sheet.suspendPaint(); sheet.setText(2, 7, "Horizontal Number Slider"); sheet.setStyle(3, 7, createSliderStyle({ marks: [0,50,100], step: 10, direction: GC.Spread.Sheets.LayoutDirection.horizontal, })); sheet.setText(2, 12, "Vertical Temperature Slider"); sheet.setStyle(3, 12, createSliderStyle({ max: 45, min: 32, marks: ["36"], step: 1, direction: GC.Spread.Sheets.LayoutDirection.vertical, formatString: "0°C" })); sheet.setText(14, 7, "Horizontal Number Range Slider"); sheet.setText(16, 6, "Start Number:"); sheet.setFormula(16, 7, '=IF(ISBLANK(H16), "", H16.start'); sheet.setText(17, 6, "End Number:"); sheet.setFormula(17, 7, '=IF(ISBLANK(H16), "", H16.end'); sheet.setColumnWidth(6,150); let rangeSliderStyle1 = createSliderStyle({ marks: [0, 50, 100], step: 10, direction: GC.Spread.Sheets.LayoutDirection.horizontal, showNumberRange: true }); rangeSliderStyle1.formatter = '=IF(ISBLANK(@), "", @.start&"~"&@.end)'; sheet.setStyle(15, 7, rangeSliderStyle1); sheet.setText(14, 12, "Vertical Number Range Slider"); sheet.setText(16, 11, "Start Number:"); sheet.setFormula(16, 12, '=IF(ISBLANK(M16), "", M16.start'); sheet.setText(17, 11, "End Number:"); sheet.setFormula(17, 12, '=IF(ISBLANK(M16), "", M16.end'); sheet.setColumnWidth(11,150); let rangeSliderStyle2 = createSliderStyle({ marks: [0, 50, 100], step: 1, direction: GC.Spread.Sheets.LayoutDirection.vertical, showNumberRange: true }); rangeSliderStyle2.formatter = '=IFERROR(@.start, 0)&"-"&IFERROR(@.end, 0)'; sheet.setStyle(15, 12, rangeSliderStyle2); sheet.resumePaint(); spread.commandManager().execute({cmd:"openSlider",row:3,col:7,sheetName:"Sheet1"}); // spread.commandManager().execute({cmd:"openSlider",row:3,col:12,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; }