views:

476

answers:

3

There are quite few solutions on Ext forums, but I wasn’t able to get any of them work. It seems I am missing something minor.

I need to resize combobox to fit its content when it’s first created. I do not need to worry about resizing it when content is changing.

Is there any working examples using Extjs 3.2?

Current Code:

var store = new Ext.data.ArrayStore({
    fields: ['view', 'value', 'defaultselect'],
    data: Ext.configdata.dataCP
});

comboCPU = new Ext.form.ComboBox({
    tpl: '<tpl for="."><div class="x-combo-list-item"><b>{view}</b><br /></div></tpl>',
    store: store,
    displayField: 'view',
    width: 600,
    typeAhead: true,
    forceSelection: true,
    mode: 'local',
    triggerAction: 'all',
    editable: false,
    emptyText: 'empty text',
    selectOnFocus: true,
    listeners: { select: AdjustPrice, change: AdjustPrice, beforeselect: function (combo, record, index) { return ('false' == record.data.disabled); } },
    applyTo: 'confelement'
});

I've also tried removing width: 600 and replacing it with minListWidth: 600 but that result following and didnt fix the issue. alt text

A: 

try autoWidth: true

and remove the width parameter

Natkeeran
there is no such config option according to documentation. http://www.extjs.com/deploy/ext/docs/output/Ext.form.ComboBox.html#configs
ITRushn
A: 

width: 600 is correct, so you must have some other issue going on that's not obvious from what you posted. You might try removing the applyTo config and instead put renderTo: Ext.getBody() just to see if it has something to do with how it's applied to your element. Are you sure there is not some other code that could be affecting the width?

bmoeskau
Well width: 600 does the job, and extend combobox to 600. Problem is that it’s always 600, but sometimes content of the options is too long and therefore not being fully display. I am looking for the way to have combobox automatically detect which width to set in order for options to always display fully.
ITRushn
A: 

I’ve found ExtJS plugin which suppose to give me what I want. Its posted on ExtJS Forums.

When I am trying to implement this plug in into my code I get "Ext.ux.ComboListAutoSizer is not a constructor" as I've described in that forum thread.

Does anybody know what might be the problem? Any help is highly appreciated.

ITRushn
That means you have not included the plugin properly. Make sure you have the correct script tag and that it is actually loading -- check the Net tab in Firebug.
bmoeskau
Everything is included and loaded properly. I was able to recreate issue using default combous.html example from ExtJS. More info on the forum.
ITRushn
Solution was finally found. Issue existed because this plugin is implemented as singleton and there fore there is no need to initiate new instance. It should be called by: plugins: [Ext.ux.ComboListAutoSizer]
ITRushn