ExtJS4 - 工具提示不显示列值

ExtJS4 - Tooltip not displaying column value

我正在尝试为网格中的每一列编写特定的工具提示。

我当前的实现无法获取悬停在其上的记录的值。如何引用行条目的特定 column/row 值?

fiddle

代码

Ext.onReady(function() {
var trackStore = new Ext.data.Store({
  storeId: 'soundCloudStore',

    proxy: {
      type: 'memory',
      data: [
          {
           title: 'Test', duration: '3434', genre: 'stuff', created_at: '2011/06/18', id: '1'   
         }
      ]
    },
    fields:['duration', 'genre', 'created_at', 'title', 'id']
});

trackStore.load(
  function() { 
    Ext.create('Ext.grid.Panel', {
      title: 'Tracks',
      store: trackStore,
      stripeRows: false,
      columns: [
        { 
            header: 'Title', 
            dataIndex: 'title'

        },
        { header: 'Duration',  dataIndex: 'duration' },
        { header: 'Genre', dataIndex: 'genre' },
        { header: 'Created At', dataIndex: 'created_at'}
      ],
      height: 200,
      width: 475,
      renderTo: Ext.getBody(),
      listeners: {
        afterrender: function( )
        {
            view = this.getView();

            view.tip = Ext.create('Ext.tip.ToolTip', {
                target: view.el,
                delegate: view.itemSelector,
                trackMouse: true,
                renderTo: Ext.getBody(),
                listeners: {
                    beforeshow: function updateTipBody(tip) {
                        tip.update(this.data.title);
                    }
                }
            });
        }
    }

  });
});
});

错误

Uncaught TypeError: Cannot read property 'title' of undefined

你可以这样做, 使用事件 "viewready" 代替 "afterrender" :

listeners: {
    viewready: function(grid) {

        var view = this.getView();

        // record the current cellIndex
        grid.mon(view, {
            uievent: function(type, view, cell, recordIndex, cellIndex, e) {
                grid.cellIndex = cellIndex;
                grid.recordIndex = recordIndex;
            }
        });

        grid.tip = Ext.create('Ext.tip.ToolTip', {
            target: view.el,
            delegate: '.x-grid-cell',
            trackMouse: true,
            renderTo: Ext.getBody(),
            listeners: {
                beforeshow: function updateTipBody(tip) {
                    console.log(grid.cellIndex);
                    if (!Ext.isEmpty(grid.cellIndex) && grid.cellIndex !== -1) {
                        header = grid.headerCt.getGridColumns()[grid.cellIndex];
                        tip.update(grid.getStore().getAt(grid.recordIndex).get(header.dataIndex));
                    }
                }
            }
        });
    }
}