admin管理员组文章数量:1026206
How to set bo box width to auto fit it's longest field option text ?
Say, I have bo box field having width 300 ..But if from that bo there is a field option having some long text - bigger than 300px.
I want to make my bo box width auto fit to that long field option to see entire selected field option in Combo without any cutting.
Actually, I forgot there is config which do same thing for bo in extjs.
I think in ExtJS 4, bo width was getting set to auto fit for longest field option.
I don't want to do it by dynamically adding code to auto resize it.
How to set bo box width to auto fit it's longest field option text ?
Say, I have bo box field having width 300 ..But if from that bo there is a field option having some long text - bigger than 300px.
I want to make my bo box width auto fit to that long field option to see entire selected field option in Combo without any cutting.
Actually, I forgot there is config which do same thing for bo in extjs.
I think in ExtJS 4, bo width was getting set to auto fit for longest field option.
I don't want to do it by dynamically adding code to auto resize it.
Share Improve this question asked Dec 14, 2015 at 10:49 Abhijit MukeAbhijit Muke 1,2143 gold badges17 silver badges41 bronze badges 1- Questions seeking code help must include the shortest code necessary to reproduce it in the question itself. See How to create a Minimal, Complete, and Verifiable example – Paulie_D Commented Dec 14, 2015 at 11:11
2 Answers
Reset to default 4No need to add any manual code..Don't give width ..
grow : true,
growToLongestValue : true
Work for me in ExtJS 6 too..
Ext.create('Ext.form.ComboBox', {
fieldLabel : 'Field',
store : ['a', 'b', 'c', 'Long long long long long long long long'],
grow : true,
growToLongestValue : true,
renderTo : Ext.getBody()
});
Check Sencha Fiddle https://fiddle.sencha./#fiddle/12jc
You would have to do it manually; it is not available in the Ext code. Something like this:
listeners: {
afterrender: function(box) {
var width = 0,
metrics = new Ext.util.TextMetrics();
box.getStore().each(function(rec) {
var recWidth = textMetrics.getWidth(rec.get(box.displayField));
width = Math.max(width,recWidth);
});
box.setWidth(width);
}
}
Without any testing or warranty, but you should get an idea how to solve it.
A detailed example how to use TextMetrics can be found in the docs.
How to set bo box width to auto fit it's longest field option text ?
Say, I have bo box field having width 300 ..But if from that bo there is a field option having some long text - bigger than 300px.
I want to make my bo box width auto fit to that long field option to see entire selected field option in Combo without any cutting.
Actually, I forgot there is config which do same thing for bo in extjs.
I think in ExtJS 4, bo width was getting set to auto fit for longest field option.
I don't want to do it by dynamically adding code to auto resize it.
How to set bo box width to auto fit it's longest field option text ?
Say, I have bo box field having width 300 ..But if from that bo there is a field option having some long text - bigger than 300px.
I want to make my bo box width auto fit to that long field option to see entire selected field option in Combo without any cutting.
Actually, I forgot there is config which do same thing for bo in extjs.
I think in ExtJS 4, bo width was getting set to auto fit for longest field option.
I don't want to do it by dynamically adding code to auto resize it.
Share Improve this question asked Dec 14, 2015 at 10:49 Abhijit MukeAbhijit Muke 1,2143 gold badges17 silver badges41 bronze badges 1- Questions seeking code help must include the shortest code necessary to reproduce it in the question itself. See How to create a Minimal, Complete, and Verifiable example – Paulie_D Commented Dec 14, 2015 at 11:11
2 Answers
Reset to default 4No need to add any manual code..Don't give width ..
grow : true,
growToLongestValue : true
Work for me in ExtJS 6 too..
Ext.create('Ext.form.ComboBox', {
fieldLabel : 'Field',
store : ['a', 'b', 'c', 'Long long long long long long long long'],
grow : true,
growToLongestValue : true,
renderTo : Ext.getBody()
});
Check Sencha Fiddle https://fiddle.sencha./#fiddle/12jc
You would have to do it manually; it is not available in the Ext code. Something like this:
listeners: {
afterrender: function(box) {
var width = 0,
metrics = new Ext.util.TextMetrics();
box.getStore().each(function(rec) {
var recWidth = textMetrics.getWidth(rec.get(box.displayField));
width = Math.max(width,recWidth);
});
box.setWidth(width);
}
}
Without any testing or warranty, but you should get an idea how to solve it.
A detailed example how to use TextMetrics can be found in the docs.
本文标签: javascriptset combo box width to auto fit it39s longest field option text in ExtJSStack Overflow
版权声明:本文标题:javascript - set combo box width to auto fit it's longest field option text in ExtJS - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745628146a2159989.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论