繁体   English   中英

ExtJS4-工具提示不显示列值

[英]ExtJS4 - Tooltip not displaying column value

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

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

小提琴

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));
                    }
                }
            }
        });
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM