-
27 Mar 2009 3:05 AM #1
Autosize width of combobox
Autosize width of combobox
Hello!
I can set the size of the dropdown-box of a combobox with listSize. This works fine. But now I want to make the dropdown-box autoadjust the width so that it fits the width of all items. How is it done?
-
27 Mar 2009 7:11 AM #2
Did you try autoWidth:true? Also, I thought I saw a suggestion from Animal to try listWidth:'auto'
Tim Ryan
Read BEFORE posting a question / BEFORE posting a Bug
Use Google to Search - API / Forum
API Doc (4.x | 3.x | 2.x | 1.x) / FAQ / 1.x->2.x Migration Guide / 2.x->3.x Migration Guide
-
27 Mar 2009 8:35 AM #3
Thanks for your reply.
autoWidth:true sets the size of the combo itself - not the dropdown-part.
listWidth:'auto' seems to work (only did some tests yet), but I thought since listWidth is declared as a number in the docs, it's not "allowed" to set it to a string. I got some bad experiences using width: 'auto' and someone here told me not to set a width to a string.
-
27 Mar 2009 8:36 AM #4
listWidth: 'auto' need an override to allow it to work cross browser.
http://extjs.com/forum/showthread.php?t=63851Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
6 Apr 2009 8:06 AM #5
I just ran into this issue and wrote something before checking the forums. However, I tested Animal's solution, and the list width seems to be the full width of the window in IE6. Here is the code that I used for an override - it is definitely more CPU intensive than Animal's solution, as it finds the max width of all the view nodes for the list.
It seems to be working in both IE6, FF3, and Chrome/SafariCode:// throw this stuff in a closure to prevent // polluting the global namespace (function(){ var originalOnLoad = Ext.form.ComboBox.prototype.onLoad; Ext.form.ComboBox.prototype.onLoad = function(){ var padding = 8; var ret = originalOnLoad.apply(this,arguments); var max = this.minListWidth || 0; var fw = false; Ext.each(this.view.getNodes(), function(node){ if(!fw){ fw = Ext.fly(node).getFrameWidth('lr'); } if(node.scrollWidth){ max = Math.max(max,node.scrollWidth+padding); } }); if( max > 0 && max-fw != this.list.getWidth(true) ){ this.list.setWidth(max); this.innerList.setWidth(max - this.list.getFrameWidth('lr')); } return ret; }; })();
Regards-
Mark
-
3 May 2009 4:51 PM #6
fabrizim, it works well, how would incorporate the combo box's width as the absolute minimun?
varsos
-
13 May 2009 5:05 AM #7
Hi varsos-
I haven't tested, but this should incorporate the boxes width as the minimum with - if minListWidth is provided, the maximum of the two is used.
Regards-
Mark
Code:// throw this stuff in a closure to prevent // polluting the global namespace (function(){ var originalOnLoad = Ext.form.ComboBox.prototype.onLoad; Ext.form.ComboBox.prototype.onLoad = function(){ var padding = 8; var ret = originalOnLoad.apply(this,arguments); var max = Math.max(this.minListWidth || 0, this.el.getWidth()); var fw = false; Ext.each(this.view.getNodes(), function(node){ if(!fw){ fw = Ext.fly(node).getFrameWidth('lr'); } if(node.scrollWidth){ max = Math.max(max,node.scrollWidth+padding); } }); if( max > 0 && max-fw != this.list.getWidth(true) ){ this.list.setWidth(max); this.innerList.setWidth(max - this.list.getFrameWidth('lr')); } return ret; }; })();
-
13 May 2009 6:46 AM #8
It seems to work ok, thanks
I had done something similar.varsos
-
3 Jan 2013 10:28 AM #9
-
4 Jan 2013 5:14 AM #10Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,641
- Vote Rating
- 434
That link is to a thread in the premium forums. You would need to purchase a support subscription in order to view that thread.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.


Reply With Quote