PDA

View Full Version : how to configure column auto width of grid?



youj2006
28 Feb 2015, 1:57 AM
Hi,
I want to configure the column will auto fit the width with the content of grid, how to realize it?

greg.barry
5 Mar 2015, 11:32 AM
You'll probably want to look into column's flex config.

It fills a ratio of width instead of a static width:
https://fiddle.sencha.com/#fiddle/j7j

Thanks!
Greg

youj2006
5 Mar 2015, 6:00 PM
Hi,
I'm going to auto fit the width with its content not screen width, as your example, I want Name column width auto get the longest conetent's width, in your case is "Homer", the column can show all content correctly and no more width needed.

greg.barry
6 Mar 2015, 1:34 PM
I see. I misunderstood your request. I believe you're looking for column's autoSize method:
http://docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/Ext.grid.column.Column-method-autoSize

I modified my fiddle:
https://fiddle.sencha.com/#fiddle/j7j

You may need to add a couple pixels to the column width after autosizing it. It looks like it's being a little too literal.

Thanks!
Greg

youj2006
7 Mar 2015, 6:12 PM
this can autosize at firsttime before grid show, but can't dynamicly autosize according to the content change.