简体   繁体   中英

How to put text and clickable icons in a Ext.Panel header?

I would like to put text and clickable icons in the headers in my panels, like this: 在此输入图像描述

I've found some old hacks from 2008 to do this , but can imagine that the newer versions of ExtJS allow you to put text and icons in panel headers in a more straightforward way.

What is the most straight-forward way to put text and clickable icons in a Ext.Panel header?

Addendum

thanks @Stefan that worked, here's my solution:

在此输入图像描述

Javascript:

var grid_shopping_cart = new Ext.grid.GridPanel({
    headerCfg: {
        tag: 'div',
        cls: 'x-panel-header',
        children: [
            { tag: 'div', cls: 'panel_header_main', 'html': 'Shopping Cart' },
            { tag: 'div', cls: 'panel_header_icon1', 'html': '<img src="images/icon_plus.png" />' },
            { tag: 'div', cls: 'panel_header_extra', 'html': 'Order Number: 2837428347' }
        ]
    },
    width: 600,
    height: 390,
    ...
    listeners: {
        'afterrender' : function(p) {
            p.header.on('click', function(e, h) {
                alert('you clicked the plus');
            }, p, {
                delegate: '.panel_header_icon1',
                stopEvent: true
            });
        },
        ...

CSS:

div.panel_header_main {
    text-align: left;
    float: left;
}

div.panel_header_extra {
    text-align: left;
    float: right;
    margin-right: 10px;
}

div.panel_header_icon1 {
    text-align: right;
    float: right;
    margin-left: 3px;
    cursor: hand;
    cursor: pointer;
}

div.panel_header_icon2 {
    text-align: right;
    float: right;
    margin-left: 3px;
    cursor: hand;
    cursor: pointer;
}

Perhaps you can use the headerCfg configuration option of the Ext.Panel :

...,
headerCfg: {
    tag: 'div',
    cls: 'x-panel-header',
    children: [
        { tag: 'div', cls: 'my-title', 'html': 'Shopping Cart' },
        { tag: 'div', cls: 'my-status', 'html': 'Status: on <img src="status.png" />' }
    ]
},
...

The clickable behavior must be added in the afterrender event for example:

function(p) {
    p.header.on('click', function(e, h) {
    }, p, {
        delegate: '.my-status',
        stopEvent: true
    });
}

You'll need some css to style the header of course...

Even more straightforward seems to be just slapping html into the title tag.

title: '<span style="cursor:help" title="' + strTitle + '">' 
    + strTitle + '</span>', 

After painfully searching up an autoEl and header workaround, this works, at least on 2.2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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