本帖最后由 Joestar.Xu 于 2024-4-2 09:31 编辑
在Excel中可以使用Alt+PageUp/PageDown快捷键来实现切换到下一页的操作,SpreadJS原生上并没有这个快捷键,要怎么实现呢?
要实现这个需求很简单,核心在于快捷键的注册和切换下一页操作的代码,以下是一个简单的示例供大家参考:
- window.onload = function () {
- let designerConfig = JSON.parse(
- JSON.stringify(GC.Spread.Sheets.Designer.DefaultConfig)
- );
- let designer = new GC.Spread.Sheets.Designer.Designer(
- "gc-designer-container",
- designerConfig
- );
- let spread = designer.getWorkbook();
- let sheet = spread.getActiveSheet();
- let pageDown = {
- canUndo: false,
- name: "pageDown",
- execute: function (context, options, isUndo) {
- let Commands = GC.Spread.Sheets.Commands;
- Commands.startTransaction(context, options);
- context
- .getActiveSheet()
- .scroll(
- 0,
- context.getHost().clientWidth -
- context
- .getActiveSheet()
- .getColumnWidth(0, GC.Spread.Sheets.SheetArea.rowHeader)
- );
- Commands.endTransaction(context, options);
- return true;
- },
- };
- let pageUp = {
- canUndo: false,
- name: "pageUp",
- execute: function (context, options, isUndo) {
- let Commands = GC.Spread.Sheets.Commands;
- Commands.startTransaction(context, options);
- context
- .getActiveSheet()
- .scroll(
- 0,
- -context.getHost().clientWidth +
- context
- .getActiveSheet()
- .getColumnWidth(0, GC.Spread.Sheets.SheetArea.rowHeader)
- );
- Commands.endTransaction(context, options);
- return true;
- },
- };
- spread
- .commandManager()
- .register("pageDown", pageDown, 34, false, false, true, false);
- spread
- .commandManager()
- .register("pageUp", pageUp, 33, false, false, true, false);
- };
复制代码
|
|