2017-02-20 28 views
0

我使用此代码在网格的每一行显示自定义工具提示。问题是我只能在一些列上显示它。我如何检索beforeshow事件中的cellIndex? 我试着tipp.triggerElement.cellIndex和tipp.anchorElement.cellIndex,但我得到了一个未定义extjs工具提示获取单元格索引

var tip = Ext.create('Ext.tip.ToolTip', { 
    // The overall target element. 
    target: grid.el, 
    // Each grid row causes its own separate show and hide. 
    delegate: grid.view.cellSelector, 
    // Moving within the row should not hide the tip. 
    trackMouse: true, 
    // Render immediately so that tip.body can be referenced prior to the first show. 
    renderTo: Ext.getBody(), 
    listeners: { 
     // Change content dynamically depending on which element triggered the show. 
     beforeshow: function updateTipBody(tipp) {    
     } 
    } 

});

回答

2

首先在你的网格selType: 'cellmodel',上放置一个配置,通过这样做,你可以使用下面的代码获得选定单元的当前位置。

grid.getSelectionModel().getCurrentPosition();

将retruns目前的行和列的详细信息以及其他一些细节一样,所以你需要在头的前show事件访问这些数据,你返回false,你没有必要表现出来。

+0

我得到了一个未定义,可你在哪里找到getCurrentPosition方法请你联系我?我无法在[docs]中找到它(http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.selection.Model) – andyts93

+1

http://docs.sencha.com/ ExtJS的/ 4.2.2 /#!/ API/Ext.selection.CellModel法,getCurrentPosition。如果它分机js 5或以上去与getPosition方法 –

2

尝试这种情况:

Ext.create('Ext.grid.Panel', { 
    listeners:{ 
     render:function(grid) { 
      var view=grid.getView(); 
      view.tip = Ext.create('Ext.tip.ToolTip', { 
       target: grid.el, 
       // this gets css query to identify the individual cells 
       delegate: view.cellSelector, 
       listeners: { 
        beforeshow: function(tip) { 
         var column = view.getGridColumns()[tip.triggerElement.cellIndex]; 
         var record = view.getRecord(tip.triggerElement.parentNode); 
         tip.update(record.get(column.dataIndex)); 
        } 
       } 
      }); 
     } 
    } 
); 
+0

我已经尝试过,但我得到的tip.triggerElement.cellIndex是undefined – andyts93

+0

好吧,我不得不添加'selType:'cellmodel''到网格,现在它的工作原理。感谢你和@ surya-prakash-tumma – andyts93

0

当我想要(的onmouseover),以在工具提示显示单元格/列的内容(例如,内容是比单元的宽度长)我使用以下渲染方法,你mabe可以适应你的情况与你想要的值:

renderer: function (value, metaData, record, rowIndex, colIndex, store, view) { 
      metaData.tdAttr = 'data-qtip= "' + value + '" data-qclass="tipCls" '; 
      return value; 
} 

在我的情况下工作很好,很简单。

看看:https://www.sencha.com/forum/showthread.php?179016-Grid-cell-tooltip

+0

我试过了,但我的工具提示是html格式的[像这样](http://i.imgur.com/gZPElqc.jpg),我无法获得相同的结果与渲染器功能。我认为它不接受data-qtip属性中的html和css标签 – andyts93

+0

先看看标注提示:http://examples.sencha.com/extjs/5.1.0/examples/qtips/qtips.html – josei

+0

而这(剑 - 它的答案;副本是代码来拨弄):https://www.sencha.com/forum/showthread.php?226358-How-to-add-a-template-to-tooltip – josei