找回密码
 立即注册

QQ登录

只需一步,快速开始

luozhu1986

初级会员

21

主题

73

帖子

451

积分

初级会员

积分
451

活字格认证

luozhu1986
初级会员   /  发表于:2014-11-13 17:11  /   查看:14960  /  回复:7
请问怎样给spreadjs 指定单元格添加事件(需求:指定单元双击或单击弹出jquery ui datepicker控件,选择日期后,能把值写入单元格)

7 个回复

倒序浏览
Alice
社区贡献组   /  发表于:2014-11-13 18:17:00
沙发
回复 1楼luozhu1986的帖子

有CellClick事件,当鼠标点击单元格的时候触发此事件。
参考代码:
Javascript (Usage)
  1. var instance; // Type: Events
  2. instance.CellClick = function(sheet, sheetName, sheetArea, row, col) { };
复制代码


Javascript (Specification)

  1. CellClick = function (
  2.    sheet : Sheet,
  3.    sheetName : string,
  4.    sheetArea : SheetArea,
  5.    row : number,
  6.    col : number
  7. ) { };
复制代码


另外可以通过hitTest方法获取鼠标点击单元格的点,从而得到单元格的index。
JavaScript:
  1. //Acquire cell index from mouse-clicked point of regular cells which are neither fixed rows/columns nor row/column headers.
  2.      var offset = $("#ss").offset();
  3.      var x = e.pageX - offset.left;
  4.      var y = e.pageY - offset.top;
  5.      var target = $("#ss").wijspread("spread").getActiveSheet().hitTest(x, y);

  6.      if(target &&
  7.          (target.rowViewportIndex === 0 || target.rowViewportIndex === 1) &&
  8.          (target.colViewportIndex === 0 || target.colViewportIndex === 1)){
  9.          console.log("Row index of mouse-clicked cells: " + target.row);
  10.          console.log("Column index of mouse-clicked cells: " + target.col);
  11.      }
复制代码
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
luozhu1986
初级会员   /  发表于:2014-11-14 11:08:00
板凳
sheet.getCell(row,col).CellClick = function(sheet, sheetName, sheetArea, row, col) {alert('click'); };
这样写对吗
回复 使用道具 举报
luozhu1986
初级会员   /  发表于:2014-11-14 11:09:00
地板
var offset = $("#ss").offset();
     var x = e.pageX - offset.left;
     var y = e.pageY - offset.top;
     var target = $("#ss").wijspread("spread").getActiveSheet().hitTest(x, y);
     ......
这样写不行
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2014-11-14 15:30:00
5#
回复 3楼luozhu1986的帖子

1.举个例子来说明如何在CellClick事件和CellDoubleClick事件中使用代码:
JavaScript
  1. $("#ss").wijspread();
  2. var spread = $("#ss").wijspread("spread");
  3. var activeSheet = spread.getActiveSheet();

  4. activeSheet.bind($.wijmo.wijspread.Events.CellClick, function (sender, args) {
  5.      if(args.sheetArea === $.wijmo.wijspread.SheetArea.colHeader){
  6.          console.log("The column header was clicked.");
  7.      }

  8.      if(args.sheetArea === $.wijmo.wijspread.SheetArea.rowHeader){
  9.          console.log("The row header was clicked.");
  10.      }

  11.      if(args.sheetArea === $.wijmo.wijspread.SheetArea.corner){
  12.          console.log("The corner header was clicked.");
  13.      }

  14.      console.log("Clicked column index: " + args.col);
  15.      console.log("Clicked row index: " + args.row);
  16. });

  17. activeSheet.bind($.wijmo.wijspread.Events.CellDoubleClick, function (sender, args) {
  18.      
  19.      if(args.sheetArea === $.wijmo.wijspread.SheetArea.colHeader){
  20.          console.log("The column header was double clicked.");
  21.      }

  22.      if(args.sheetArea === $.wijmo.wijspread.SheetArea.rowHeader){
  23.          console.log("The row header was double clicked.");
  24.      }

  25.      if(args.sheetArea === $.wijmo.wijspread.SheetArea.corner){
  26.          console.log("The corner header was double clicked.");
  27.      }

  28.      console.log("Double clicked column index: " + args.col);
  29.      console.log("Double clicked row index: " + args.row);
  30. });
复制代码


2.你说的不行,是指该事件没有触发,还是hitTest执行后没有得到你想要的结果?
你的代码是如何实现的,hitTest方法是通过什么位置获取的。
再举个例子阐述如何使用hitTest方法:
  1. $("#spreadContainer").click(function (e) {
  2.     //Acquire cell index from mouse-clicked point of regular cells which are neither fixed rows/columns nor row/column headers.
  3.     var offset = $("#spreadContainer").offset();
  4.     var x = e.pageX - offset.left;
  5.     var y = e.pageY - offset.top;
  6.     var target = $("#spreadContainer").wijspread("spread").getActiveSheet().hitTest(x, y);

  7.     if(target &&
  8.         (target.rowViewportIndex === 0 || target.rowViewportIndex === 1) &&
  9.         (target.colViewportIndex === 0 || target.colViewportIndex === 1)){
  10.         alert("Row index of mouse-clicked cells: " + target.row);
  11.         alert("Column index of mouse-clicked cells: " + target.col);
  12.     }
  13. });
复制代码
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
luozhu1986
初级会员   /  发表于:2014-11-18 15:35:00
6#
回复 5楼Alice的帖子

第一个问题,我只需给指定单元格添加事件,而不是所有单元格

第二个问题,我是copy你给出的代码

我要实现的需求,给指定单元格绑定一个jqueryUI日期控件,
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-11-18 19:54:00
7#
回复 6楼luozhu1986的帖子

问题已经查收,明天调查后反馈结果。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-11-19 10:47:00
8#
回复 6楼luozhu1986的帖子

问题一,可以根据当前行列索引判断是否为目标单元格,进而实现特定单元格点击效果。
问题二,目前 SpreadJS 没有提供日期单元格类型,不过开放了自定义单元格类型接口,需要你进行自定义,参考链接:
http://helpcentral.componentone. ... tml#cellcustom.html
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部