找回密码
 立即注册

QQ登录

只需一步,快速开始

oraclexp79

初级会员

27

主题

45

帖子

220

积分

初级会员

积分
220
oraclexp79
初级会员   /  发表于:2019-4-18 10:22  /   查看:3055  /  回复:6
如题,我想要实现的功能是栏位列头上显示中文字段名称,title悬浮显示的是英文字段名称,请问有能实现如div title一样功能的方法吗

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

6 个回复

倒序浏览
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2019-4-18 18:16:04
沙发
您好,可以给FlexGrid添加鼠标事件,如代码所示:


  1. // monitor and log mouse moves
  2.         var logEl = document.getElementById('log');
  3.         theGrid.addEventListener(theGrid.hostElement, 'click', function(e) {
  4.             var ht = theGrid.hitTest(e);
  5.             alert("点击行:"+ ht.row);
  6.         });
复制代码


通过hitTest方法可以获取到行、列坐标,然后用tooltip进行显示,参考API:

https://www.grapecity.com/wijmo/api/classes/wijmo.tooltip.html
回复 使用道具 举报
oraclexp79
初级会员   /  发表于:2019-4-18 19:02:02
板凳
目前我的版本是wijmo-5.20183.550 ,是否支持es6写法?你给我的参考是es6写法
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2019-4-19 10:39:32
地板
您好,这个不影响的,您可以用ES5的语法来实现,示例代码如下:


  1.     onload = function() {

  2.         // create some random data
  3.         var countries = 'US,Germany,UK,Japan'.split(',');
  4.         var data = [];
  5.         for (var i = 0; i < 20; i++) {
  6.             data.push({
  7.                 id: i,
  8.                 country: countries[i % countries.length],
  9.                 sales: Math.random() * 10000,
  10.                 expenses: Math.random() * 5000,
  11.                 overdue: i % 4 == 0
  12.             });
  13.         }

  14.         // bind a grid to the data
  15.         var theGrid = new wijmo.grid.FlexGrid('#theGrid', {
  16.             itemsSource: new wijmo.collections.CollectionView(data, {
  17.                 groupDescriptions: [ 'country' ] // group data by country
  18.             }),
  19.             formatItem: function(s, e) {  // add 'button' to country cells
  20.                 if (e.panel == s.cells) {
  21.                     if (s.columns[e.col].binding == 'country') {
  22.                         var html = '<span class="my-button">&#x2b24;</span> ' + e.cell.innerHTML;
  23.                         e.cell.innerHTML = html;
  24.                     }
  25.                 }
  26.             }
  27.         });
  28.         
  29.         theGrid.addEventListener(theGrid.hostElement, 'mouseover', function(e) {
  30.             var ht = theGrid.hitTest(e);
  31.             var cellType = ht.cellType;
  32.             // 判断是否为列头的cellType
  33.             if(cellType === 2){
  34.                 console.log(theGrid.getClipString(ht.range, true, true));
  35.             }
  36.         });
  37.     }
复制代码


回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2019-4-19 10:41:20
5#
完整示例我上传到附件中了,您可以下载参考一下。


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
oraclexp79
初级会员   /  发表于:2019-4-19 10:53:10
6#
谢谢,经过你们的帮助,问题解决,不过我没用tooltip,用了自己的方法
                 var columnHeaderList=[{"id":"Executant","name":"执行者"}];//对应中英文
                         this.eventGrid.addEventListener(this.eventGrid.hostElement,'mousemove', function (e) {
                                  var ht = _this.eventGrid.hitTest(e);
                 // 判断是否为列头的cellType
                                  if(ht.cellType==2){
                                           $(".wj-colheaders .wj-row .wj-header").each(function() {
                                      var txt =$(this).text() ;
                                                  if (txt != "") {
                                                   var item = columnHeaderList.find(p=>p.id==txt);
                                                   if(item!=null) txt = item.name;
                                                    $(this).attr("title", txt);
                                                  }
                                   
                                            })
                                  }
                        });

评分

参与人数 1金币 +1000 收起 理由
KevinChen + 1000 感谢反馈和分享!

查看全部评分

回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2019-4-25 10:54:38
7#
不客气,很高兴您最终解决了问题,本帖结贴了~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部