找回密码
 立即注册

QQ登录

只需一步,快速开始

Derrick.Jiao 讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2021-3-4 09:41  /   查看:2465  /  回复:0
背景:相信有小伙伴在用在线表格编辑器的时候都有用到数据绑定的功能。数据绑定中,有一个可以拖放字段的功能,拖放到指定单元格后,单元格会显示字段。有小伙伴也想在自己的表单指定单元格中显示指定的字段,那么我们可以用自定义单元格实现。
实现效果如下
image.png237982787.png

这是关键代码
  1. var spreadNS = GC.Spread.Sheets;

  2. function BindingPathCellType() {
  3.                 spreadNS.CellTypes.Text.call(this);
  4.             }
  5.             BindingPathCellType.prototype = new spreadNS.CellTypes.Text();
  6.             BindingPathCellType.prototype.paint = function (ctx, value, x, y, w, h, style, context) {
  7.                 if (value === null || value === undefined) {
  8.                     var sheet = context.sheet, row = context.row, col = context.col;
  9.                     if (sheet && (row === 0 || !!row) && (col === 0 || !!col)) {
  10.                         var bindingPath = sheet.getBindingPath(context.row, context.col);
  11.                         if (bindingPath) {
  12.                             value = "[" + bindingPath + "]";
  13.                         }
  14.                     }
  15.                 }
  16.                 spreadNS.CellTypes.Text.prototype.paint.apply(this, arguments);
  17.             };
复制代码


当然,我们的表格绑定中也有这样的一个示例,大家可以到下方链接查看
https://demo.grapecity.com.cn/sp ... able-binding/purejs

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部