2017-02-20 47 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