EXTJS 给grid添加tooltip

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
dockedItems: [{
        xtype:'pagingtoolbar',
        dock:'bottom',
        displayInfo:true,
        store:'Countries',
        items: [
                {
                    xtype:'tbseparator'
                },
                {
                    id :'myTip1',
                    xtype :'button',
                    text:'ToolTip Example 1',
                    tooltip:'Tool Tip added in the View definition ...'
                },
                {
                    id :'myTip2',
                    xtype :'button',
                    text:'ToolTip Example 2',
                }
        ]
    }],

Here is how to add the ToolTip for second button from the controller. This way you have more control over the text to display and when to display.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
init :function() {
  this.control({
    
     ......
     ......
   'countryList button[id=myTip2]': {
    render :this.onButtonRendered
   }
    
  });
 },
 
onButtonRendered :function() {
 console.log('The ToolTip Button was rendered');
 //create the ToolTip
 Ext.create('Ext.tip.ToolTip', {
  target:'myTip2',
  html:'Tool Tip added later from the app controller ...'
 });
}

Display ToolTip for Grid Cell using custom renderer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
initComponent:function() {
        
        this.columns = [{
            header:'Country Code',
            dataIndex:'code',
            flex: 1,
            renderer :function(value, metadata, record) {
                myToolTipText ="<b>Tool Tip added using renderer function for country</b>";
                myToolTipText = myToolTipText +"
Code: "+ record.get('name');
                myToolTipText = myToolTipText +"
Name: "+ record.get('name');
                myToolTipText = myToolTipText +"
Continent: "+ record.get('continent');
                myToolTipText = myToolTipText +"
Region: "+ record.get('region');
                metadata.tdAttr ='data-qtip="'+ myToolTipText +'"';
                returnvalue;
            }
        },
            {header:'Name', dataIndex:'name', flex: 3}
        ];
        this.callParent(arguments);
    }
});

Display ToolTip dynamically for Grid Cell using delegation

With delegation you can attach one ToolTip to many elements under a common parent. This is more efficient than creating many ToolTip instances. To do this, point the target config to a common ancestor of all the elements, and then set the delegate config to a CSS selector that will select all the appropriate sub-elements.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//create the ToolTip
gridView.tip = Ext.create('Ext.tip.ToolTip', {
 // The overall target element.
 target: gridView.el,
 // Each grid row causes its own seperate show and hide.
 delegate: gridView.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:functionupdateTipBody(tip) {
   gridColums = gridView.view.getGridColumns();
   column = gridColums[tip.triggerElement.cellIndex];
   //only display the tool tip for name column
   if(column.dataIndex ==='name'){
    record = gridView.view.getRecord(tip.triggerElement.parentNode);
    myToolTipText ="<b>Tool Tip for country added from the controller</b>";
    myToolTipText = myToolTipText +"
Code: "+ record.get('name');
    myToolTipText = myToolTipText +"
Name: "+ record.get('name');
    myToolTipText = myToolTipText +"
Continent: "+ record.get('continent');
    myToolTipText = myToolTipText +"
Region: "+ record.get('region');
    tip.update(myToolTipText);
   }
   else{
    returnfalse;
   }
  }
 }
});

Tip: If you don't care about the individual cell or columns and want to display the same ToolTip for any cell in the record then you can use the itemSelector instead of cellSelector. Here are the changes to the delegate and the beforeshow functions ...
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    delegate: gridView.view.itemSelector,
 
 
    beforeshow:functionupdateTipBody(tip) {
        record = gridView.view.getRecord(tip.triggerElement);
        myToolTipText ="<b>Tool Tip for country added from the controller</b>";
                myToolTipText = myToolTipText +"
Code: "+ record.get('name');
                myToolTipText = myToolTipText +"
Name: "+ record.get('name');
                myToolTipText = myToolTipText +"
Continent: "+ record.get('continent');
                myToolTipText = myToolTipText +"
Region: "+ record.get('region');
                tip.update(myToolTipText);
    }

Some important configs for Ext.tip.ToolTip

  • autoHide
    • True to automatically hide the tooltip after the mouse exits the target element or after the dismissDelay has expired if set. If closable = true a close tool button will be rendered into the tooltip header.
    • Defaults to: true
  • dismissDelay
    • Delay in milliseconds before the tooltip automatically hides. To disable automatic hiding, set dismissDelay = 0.
    • Defaults to: 5000
  • closable
    • True to render a close tool button into the tooltip header.
    • Defaults to: false
  • trackMouse
    • True to have the tooltip follow the mouse as it moves over the target element.
    • Defaults to: false
  • anchor
    • If specified, indicates that the tip should be anchored to a particular side of the target element or mouse pointer ("top", "right", "bottom", or "left"), with an arrow pointing back at the target or mouse pointer.
  • contentEl
    • Specify an existing HTML element, or the id of an existing HTML element to use as the content for this component.
  • title
    • The title text to be used to display in the panel header. When a title is specified the Ext.panel.Header will automatically be created and displayed unless preventHeader is set to true.
    • Defaults to: ""

转载于:https://my.oschina.net/u/852387/blog/346230

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值