找回密码
 立即注册

QQ登录

只需一步,快速开始

boy

注册会员

16

主题

35

帖子

135

积分

注册会员

积分
135
boy
注册会员   /  发表于:2021-11-11 17:36  /   查看:2377  /  回复:8
1金币
本帖最后由 Lynn.Dou 于 2021-11-15 12:26 编辑
  1. function DatePickerCellType() {

  2. }

  3. DatePickerCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();

  4. DatePickerCellType.prototype.createEditorElement = function () {

  5.         //Create input presenter.

  6.         var input = document.createElement("input");

  7.         return input;

  8. };

  9. DatePickerCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect) {

  10.         //Initialize input editor.

  11.         if (editorContext) {

  12.                 $editor = $(editorContext);

  13.                 GC.Spread.Sheets.CellTypes.Base.prototype.activateEditor.apply(this, arguments);

  14.                 $editor.datetimepicker();

  15.                 $editor.css("position", "absolute");

  16.                 $editor.attr("gcUIElement", "gcEditingInput");

  17.                 $(".ui-datetimepicker").attr("gcUIElement", "gcEditingInput");

  18.         }

  19. }

  20. DatePickerCellType.prototype.deactivateEditor = function (editorContext) {

  21.         //Remove input editor when end editor status.

  22.         if (editorContext) {

  23.                 var element = editorContext;

  24.                 $(element).datetimepicker("hide");

  25.                 $(element).datetimepicker("destroy");

  26.         }

  27.         GC.Spread.Sheets.CellTypes.Base.prototype.deactivateEditor.apply(this, arguments)

  28. };

  29. DatePickerCellType.prototype.setEditorValue = function (editor, value) {

  30.         //Sync value from Cell value to editor value.

  31.         $(editor).datetimepicker("setDate", value);

  32. };

  33. DatePickerCellType.prototype.getEditorValue = function (editor) {

  34.         //Sync value from editor value to cell value.

  35.         return $(editor).datetimepicker("getValue");

  36. };

  37. DatePickerCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect) {

  38.         if (editorContext) {

  39.                 $editor = $(editorContext);

  40.                 $editor.css("width", cellRect.width - 1);

  41.                 $editor.css("height", cellRect.height - 3);

  42.         }

  43. };
复制代码
基于这个例子:https://demo.grapecity.com.cn/SpreadJS/cdn/extendedExample/#/demos/datePickerCell
依赖jQuery-datetimepicker 始终无法将选择的日期填入单元格,getEditorValue 方法始终无法拿到日期值


image.png81422118.png
jquery-datetimepicker:  https://xdsoft.net/jqplugins/datetimepicker/
image.png653947143.png




dateTimePicker.zip

53.81 KB, 下载次数: 76

8 个回复

倒序浏览
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-11-11 18:37:39
沙发
您好,
需要先根据您提供的代码整理为demo,尝试复现此问题,
这需要一定的时间,待有结果会在本贴回复您。

您可以直接提供一个可复现可运行demo,这样能更快的复现问题。
回复 使用道具 举报
boy
注册会员   /  发表于:2021-11-11 18:46:14
板凳
Lynn.Dou 发表于 2021-11-11 18:37
您好,
需要先根据您提供的代码整理为demo,尝试复现此问题,
这需要一定的时间,待有结果会在本贴回复您 ...

这个dateTimePicker.zip
回复 使用道具 举报
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-11-12 14:29:16
地板
本帖最后由 Lynn.Dou 于 2021-11-12 14:53 编辑

经调研,这是由于datetimepicker组件的生命周期与SJS自定义单元格周期不一致。
在执行至 getEditorValue 方法时,此时datetimepicker组件的选择日期还未获取到,
所以最终返回的value为null。
这边需要调研下是否有其他方案,待有结果会在贴中通知您。
本贴先做保留处理。
回复 使用道具 举报
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-11-23 11:11:37
5#
经调研,可以修改为以下代码解决此问题:
  1. DatePickerCellType.prototype.activateEditor = function(editorContext, cellStyle, cellRect) {
  2.             //Initialize input editor.
  3.             if (editorContext) {
  4.                 $editor = $(editorContext);
  5.                 GC.Spread.Sheets.CellTypes.Base.prototype.activateEditor.apply(this, arguments);
  6.                 $editor.datetimepicker();
  7.                 $editor.css("position", "absolute");
  8.                 $editor.attr("gcUIElement", "gcEditingInput");
  9.                 $(".xdsoft_datetimepicker").attr('gcUIElement', "gcEditingInput");
  10.             }
  11.         }
复制代码
不过这种方式下,选择日期之后不能直接关闭日期控件,需要点击其他单元格来关闭。
除此目前没有更好的解决方案了。
回复 使用道具 举报
boy
注册会员   /  发表于:2021-11-23 11:26:33
6#
Lynn.Dou 发表于 2021-11-23 11:11
经调研,可以修改为以下代码解决此问题:不过这种方式下,选择日期之后不能直接关闭日期控件,需要点击其他 ...

除了使用 jquery-datetimepicker 还能使用其他的日期时间选择框支持分钟的选择吗
回复 使用道具 举报
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-11-23 12:04:45
7#
这边未对日期时间选择框控件做相关研究,所以无法给出合适的建议,
您可以实际调研测试下。
回复 使用道具 举报
小弟弟
初级会员   /  发表于:2023-4-6 13:54:45
8#
问下楼主最后用的是什么其他的日期时间选择器啊
回复 使用道具 举报
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2023-4-6 18:13:34
9#
如果需要一般的时间选择,建议就使用我们内置的日期时间下拉框
https://demo.grapecity.com.cn/sp ... -time-picker/purejs

楼主这边用的是自定义单元格
https://demo.grapecity.com.cn/Sp ... emos/datePickerCell
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部