DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Frameworks
  4. ExtJS 4: How to Add Tooltip to Grid Header

ExtJS 4: How to Add Tooltip to Grid Header

This tutorial will walk through out how to add a tooltip to a Grid Header.

Loiane Groner user avatar by
Loiane Groner
·
Oct. 07, 11 · Tutorial
Like (0)
Save
Tweet
Share
20.25K Views

Join the DZone community and get the full member experience.

Join For Free

this tutorial will walk through out how to add a tooltip to a grid header. this feature is not natively supported by ext js 4 api. fortunately,  there is a third-party plugin we can use to do it.

to get started, i created a javascript project on eclipse ide and it looks like this:

plugin code

the first thing we have to add (after ext js 4 sdk) is the plugin. to do so, i created a folder ux (for plugins) and a folder called grid (inside ux) because it is a plugin for ext 4 grid. then i created a file name headertooltip.js with the following content:

/**
 * @class ext.ux.grid.headertooltip
 * @namespace ux.grid
 *
 *  text tooltips should be stored in the grid column definition
 *
 *  sencha forum url:
 *  http://www.sencha.com/forum/showthread.php?132637-ext.ux.grid.headertooltip
 */
ext.define('ext.ux.grid.headertooltip', {
    alias: 'plugin.headertooltip',
    init : function(grid) {
        var headerct = grid.headerct;
        grid.headerct.on("afterrender", function(g) {
            grid.tip = ext.create('ext.tip.tooltip', {
                target: headerct.el,
                delegate: ".x-column-header",
                trackmouse: true,
                renderto: ext.getbody(),
                listeners: {
                    beforeshow: function(tip) {
                        var c = headerct.down('gridcolumn[id=' + tip.triggerelement.id  +']');
                        if (c  && c.tooltip)
                            tip.update(c.tooltip);
                        else
                            return false;
                    }
                }
            });
        });
    }
});

grid with header tooltip

now we need to build the application code. to test, simply create a data grid:

ext.loader.setconfig({enabled: true});

ext.require([
    'ext.grid.*',
    'ext.data.*',
    'ext.ux.grid.headertooltip'
]);

ext.onready(function() {

    var mydata = [
        ['3m co'],
        ['alcoa inc'],
        ['altria group inc'],
        ['american express company'],
        ['american international group, inc.'],
        ['at&t inc.'],
        ['boeing co.'],
        ['caterpillar inc.'],
        ['citigroup, inc.'],
        ['e.i. du pont de nemours and company'],
        ['exxon mobil corp'],
        ['general electric company']
    ];

    var store = ext.create('ext.data.arraystore', {
        fields: [
           {name: 'company'}
        ],
        data: mydata
    });

    ext.create('ext.grid.panel', {
        store: store,
        plugins: ['headertooltip'],
        columns: [
            {
                text     : 'company',
                flex     : 1,
                sortable : false,
                dataindex: 'company',
                tooltip: 'some tooltip'
            }
        ],
        height: 200,
        width: 200,
        title: 'grid with header tooltip',
        renderto: 'grid-example',
        viewconfig: {
            striperows: true
        }
    });
});

on line 1, we have to enable the ext.loader so ext can dynamic loading the files we need.

on lines 3-7 we declared the components we need to have loaded before loading our application. note the ext.ux.grid.headertooltip.js is included as well. this way, ext js knows it has to look for a file called headertooltip.js inside the folder ux/grid.

then on line 35 we have to include the headertooltip plugin as a plugin of the grid we want to display a header tooltip.

and finally, on line 42 we need to declared a column config called tooltip with the header tooltip we want to display.

html page

then we can create an html file we can run on a browser:

<html>
<head>
    <title>grid with header tooltip</title>

    <link rel="stylesheet" type="text/css" href="ext4/resources/css/ext-all.css" />
    <script type="text/javascript" src="ext4/ext-all.js"></script>

    <script type="text/javascript" src="app.js"></script>
</head>
<body>
    <div id="grid-example" style="padding:20px;"></div>
</body>
</html>

and when we execute the application, we will get the following:

and it is done!

disclaimer : i am not the author of this headertooltip plugin. so if you get any errors, please contact the author of the plugin on sencha forum: http://www.sencha.com/forum/showthread.php?132637-ext.ux.grid.headertooltip . i simply demonstrated how to use the plugin on this tutorial.

i’m using ext js 4.0.2a (open source version) on this project.

download the source code:

you can download the source code from:

my github: https://github.com/loiane/extjs4-grid-header-tooltip

happy coding! :)

  • subscribe to the comments for this post?
  • post to delicious
  • post to digg
  • post to twitter
    2
    2
    2
    2
    2
    2
    2
    2
    2
  • add to dzone
  • post to facebook
    1
    1
    1
    1
    1
    1
    1
    1
    1
  • add to linkedin
  • send via gmail
  • add to reddit
  • post to stumbleupon
  • add to technorati favorites
  • post on google buzz
  • share on google reader
  • add to google bookmarks
  • send via yahoo mail
  • add to friendfeed
  • post to blogmarks
  • post to yc hacker news
get shareaholic for firefox

from http://loianegroner.com/2011/10/extjs-4-how-to-add-tooltip-to-grid-header

Ext JS POST (HTTP)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Scaling Your Testing Efforts With Cloud-Based Testing Tools
  • What Are the Different Types of API Testing?
  • Steel Threads Are a Technique That Will Make You a Better Engineer
  • Introduction to NoSQL Database

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: