找回密码
 立即注册

QQ登录

只需一步,快速开始

lin123

最新发帖
Clark.Pan讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2018-3-20 10:03:15
7#
lin123 发表于 2018-3-20 09:30
还是有问题,在单元格输入数字以后没有显示数字?是个空白的单元格,getEditorValue有问题

textarea 改的地方不只是一处,您将您的代码和我的代码diff一下就能看出修改的地方了
回复 使用道具 举报
Clark.Pan讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2018-3-20 10:02:19
6#
lin123 发表于 2018-3-19 18:40
你好,能限制输入了,我用的好像是v11的,能请教一下您改在哪些地方?是不是就createEditorElement里面的 ...

对V9的输入框用的是textarea 目前统一改成DIV显示了,所以原来的方法不适用了
回复 使用道具 举报
lin123
中级会员   /  发表于:2018-3-20 09:30:18
5#
本帖最后由 lin123 于 2018-3-20 09:56 编辑
ClarkPan 发表于 2018-3-19 18:07
您好:
之前demo是V9的写法,V10中接口有做一些修改,参考下面的写法,这个是修改过后的:

还是有问题,在单元格输入数字以后没有显示数字?是个空白的单元格,getEditorValue有问题
回复 使用道具 举报
lin123
中级会员   /  发表于:2018-3-19 18:40:56
地板
本帖最后由 lin123 于 2018-3-20 09:53 编辑
ClarkPan 发表于 2018-3-19 18:07
您好:
之前demo是V9的写法,V10中接口有做一些修改,参考下面的写法,这个是修改过后的:

你好,能限制输入了,我用的好像是v11的,能请教一下您改在哪些地方?是不是就createEditorElement里面的textarea 有问题
回复 使用道具 举报
Clark.Pan讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2018-3-19 18:07:05
板凳
您好:
之前demo是V9的写法,V10中接口有做一些修改,参考下面的写法,这个是修改过后的:
  1. window.onload = function() {
  2.           var spread = new GC.Spread.Sheets.Workbook($("#ss")[0], { sheetCount : 1 });
  3.           var sheet = spread.getActiveSheet();
  4.           //非数字禁止输入
  5.           function NumberCellType() {
  6.           }
  7.           NumberCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  8.           NumberCellType.prototype.paint = function(ctx, value, x, y, w, h,style, options) {
  9.            if (value) {
  10.                 GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, [ctx, value, x, y, w, h, style, options ]);
  11.            }
  12.           };
  13.           NumberCellType.prototype.updateEditor = function(editorContext,  cellStyle, cellRect) {
  14.            if (editorContext) {
  15.                 $(editorContext).width(cellRect.width);
  16.                 $(editorContext).height(100);
  17.                 return {  height : 100 };
  18.            }
  19.           };
  20.           NumberCellType.prototype.createEditorElement = function(context) {
  21.            var editor = GC.Spread.Sheets.CellTypes.Text.prototype.createEditorElement.call(this, context);
  22.            //var textarea = editor.firstChild;
  23.            editor.onkeypress = function(event) {
  24.                 return event.keyCode >= 48 && event.keyCode <= 57 || event.keyCode == 46
  25.            }
  26.            editor.onkeyup = function(event) {
  27.                 this.value = this.value.replace(/[\u4e00-\u9fa5]/g, '').replace(/\D/g, '');
  28.            }
  29.            editor.onpaste = function(event) {
  30.                 var clipData = event.clipboardData;
  31.                 return !clipData.getData('text').match(/\D/);
  32.            }
  33.            editor.ondragenter = function(event) {
  34.                 return false;
  35.            }
  36.            return editor;
  37.           };
  38.           NumberCellType.prototype.getEditorValue = function(editorContext) {
  39.            if (editorContext) {
  40.                 var input1 = editorContext;
  41.                 var value = $(input1).val();
  42.                 return value;
  43.            }
  44.           };
  45.           NumberCellType.prototype.setEditorValue = function(editorContext, value) {
  46.            if (editorContext && value) {
  47.                 var input1 = editorContext;
  48.                 $(input1).val(value);
  49.            }
  50.           };
  51.           NumberCellType.prototype.isReservedKey = function(e) {
  52.            return (e.keyCode === GC.Spread.Commands.Key.tab && !e.ctrlKey&& !e.shiftKey && !e.altKey);
  53.           };
  54.           NumberCellType.prototype.isEditingValueChanged = function(oldValue,  newValue) {
  55.            if (newValue != oldValue) {
  56.                 return true;
  57.            }
  58.            return false;
  59.           };
  60.           var numberCellType = new NumberCellType();
  61.           sheet.getCell(0,3).value("11");
  62.           sheet.getRange(1,3,5,1).cellType(numberCellType);
  63.         }
复制代码
回复 使用道具 举报
lin123
中级会员   /  发表于:2018-3-19 14:53:10
沙发
回复 使用道具 举报
12345
您需要登录后才可以回帖 登录 | 立即注册
返回顶部