5

I am using below code to display Tool Tip for Grid cell In ExtJS 6

{
header: 'Name', 
cls: 'nameCls',
locked: true,
tdCls: 'nameTdCls',
dataIndex: 'name',
renderer: function (value, metaData, record, rowIndex, colIndex, store, view) {
    metaData.tdAttr = 'data-qtip= "' + value + '" data-qclass="tipCls" data-qwidth=200';
    return value;
}}

When i run the application it doesnt show the tooltip and display below error message. JS Console Error on cell mouse hover

Any idea guys??

Thanks in advance guys.

Regards, Mahendra

4
  • It seems the tooltip class is missing. Have you called Ext.QuickTips.init();? Commented Sep 10, 2016 at 18:40
  • @Tyr No i havent call Ext.QuickTips.init(); where should i call this method? Commented Sep 11, 2016 at 11:26
  • Call it on Ext.onReady(function(){ /*here*/ }) Commented Sep 12, 2016 at 6:36
  • Hi @Vinod Gubala.. I tried the same but still getting the same error. Commented Sep 12, 2016 at 11:35

3 Answers 3

10

Have you tried creating an Ext.tip.ToolTip? You can create a single one to serve as tooltip for each name cell (using delegate) and update it with the value of that cell. Set up a grid render listener to create the tooltip like this:

render: function(grid) {
  var view = grid.getView();

  grid.tip = Ext.create('Ext.tip.ToolTip', {
    target: view.getId(),
    delegate: view.itemSelector + ' .nameTdCls',
    trackMouse: true,
    listeners: {
      beforeshow: function updateTipBody(tip) {
        var tipGridView = tip.target.component;
        var record = tipGridView.getRecord(tip.triggerElement);

        tip.update(record.get('name'));
      }
    }
  });
}

For a working example, see this Fiddle.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your reply. I forget to mention one point that i am using locked grid. In my grid initial 3 columns are locked & remaning are unlocked. For locked columns i have used "locked: true" property. When i put the same in your example it stops working. Any idea why it is not working when i add one column as locked.
Check the updated Fiddle. A grid behaves differently when using enableLocking. The API docs for enableLocking say this: "A locking grid is processed in a special way. <snip> This Panel becomes merely a container which arranges both in an HBox layout.". I've changed the example a bit, mostly by moving the render listener to lockedViewConfig. Take a look.
1

Thanks for Robert Klein Kromhof!

grid columns:

columns: [{..., tdCls: 'tip'}]

grid listeners:

render: function (grid) {
                var view = grid.getView();
                grid.tip = Ext.create('Ext.tip.ToolTip', {
                    target: view.getId(),
                    delegate: view.itemSelector + ' .tip',
                    trackMouse: true,
                    listeners: {
                        beforeshow: function (tip) {
                            var tipGridView = tip.target.component;
                            var record = tipGridView.getRecord(tip.triggerElement);
                            var colname = tipGridView.getHeaderCt().getHeaderAtIndex(tip.triggerElement.cellIndex).dataIndex;
                            tip.update(record.get(colname));
                        }
                    }
                });
            },
            destroy: function (view) {
                delete view.tip;
            }

Comments

0

Create independent function and call when you need.

var grid = Ext.getCmp('your_grid_id');   // Enter your grid id
initToolTip(grid); // call function

initToolTip: function(grid) {
    var view = grid.view;

    // 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) {
                if (!Ext.isEmpty(grid.cellIndex) && grid.cellIndex !== -1) {
                    header = grid.headerCt.getGridColumns()[grid.cellIndex];
                    columnText = grid.getStore().getAt(grid.recordIndex).get(header.dataIndex);

                    tip.update(columnText);
                }
            }
        }
    });
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.