开发者

Icon In ExtJs Combo

How to display Icon along with display field in ExtJs Combo.Is There any extension fo开发者_如何学运维r extjs combo. Please provide some samples.


For ExtJS4 add a listConfig with getInnerTpl Method to the combobox:

xtype: 'combobox',
anchor: '100%',
listConfig: {
  getInnerTpl: function(displayField) {
    return '<img src="/images/icons/{id}.png" class="icon"/> {' + displayField + '}';
  }
},
name: 'type',
fieldLabel: 'Group Type',
displayField: 'label',
hiddenName: 'type',
queryMode: 'local',
store: 'group.Types',
valueField: 'id'


Refer this :

Workaround-Image-in-Combobox-options

Country selector with flag images in ExtJS


Another way, I think is possible to improve it but works ok for me:

  ,store: new Ext.data.ArrayStore({
              id: 0,
              fields: [
                'lang', 'desc','url'
             ],
             data: [['CA','Spanish','es.gif'],['VA','Valencian','va.gif']]
 })

 ,tpl : '<tpl for=".">'+
                 '<tpl if="0==0"><div class="x-combo-list-item" ><img src="../img/{url}">       {desc}</div></tpl>'+
                '</tpl>'


Here you can see how to display an icon with a clickable function. I'm using getInnerTpl to change the tpl rows inside the combo. While creating a new tpl I can change the html so it will include a css class that load in runtime the icon I want

comboBox = Ext.create('Ext.form.ComboBox', {
            cls: 'fancy',
            itemId: 'itemId',
            store: store,
            displayField: 'displayField',
            valueField: 'InstanceId',
            editable: false,
            padding: '5 4 0 0',
            queryMode: 'local',
            lastQuery: '',
            listConfig: {
                maxHeight: 85,
                getInnerTpl: function (displayField) {
                    scope: me;
                    var tpl = '<tpl for=".">'
                                + '<div data-qtip={' + displayField + '}>'
                                    + '<div class="ItemClickSigh">{' + displayField + '}</div>'
                                    + '<div style="display: inline-block; float: right;">'
                                        + '<div class="EditIcon"></div>&nbsp;'
                                    + '</div>'
                                + '</div>'
                            + '</tpl>';

                    return tpl;
                },
                listeners: {
                    itemclick: function (list, record, item, index, e) {
                        scope: me;
                        me.hendlerComboItemClicked(record, e);
                    },
                    itemmouseenter: function (cmb, record, item, index, e, eOpts) {
                        scope: me;
                        me.hendlerComboItemMouse(item, 'visible');
                    },
                    itemmouseleave: function (cmb, record, item, index, e, eOpts) {
                        scope: me;
                        me.hendlerComboItemMouse(item, 'hidden');
                    }
                }
            }
        });

Css:

.IA_EditIcon {
background-image: url('url')!important;
background-repeat:no-repeat;
width:16px;
height:16px;
cursor: pointer;
margin-right: 5px;
margin-bottom: 0px;
float: left;
display: inline;    
visibility: hidden;

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜