PDA

View Full Version : ExtJS 4.2.1 column autosize won't work



ilmcon
30 Dec 2013, 5:00 AM
Hi there,
whenever i try to automatically adjust the column size with column,autoSize() i get an error and the grid is not displayed correctly. I added a Listener to the view of the grid so that it automatically checks, if a column should be autosized or not. Here is my code:


this.getView().addListener('refresh', function (view) {
Ext.each(view.panel.headerCt.columnManager.columns, function (c) {
if (c.autoWidth) c.autoSize();
console.log(c);
});
});

And Chrome tells me this:


msg: Uncaught TypeError: Cannot read property 'dom' of undefined


url: http://ilmcon/js/resources/extjs/ext-all-debug.js


line: 106058


stack: TypeError: Cannot read property 'dom' of undefined
at Ext.define.getMaxContentWidth (http://ilmcon/js/resources/extjs/ext-all-debug.js:106058:33)
at Ext.define.autoSizeColumn (http://ilmcon/js/resources/extjs/ext-all-debug.js:106034:34)
at Ext.define.autoSizeColumn (http://ilmcon/js/resources/extjs/ext-all-debug.js:109429:18)
at Ext.define.autoSize (http://ilmcon/js/resources/extjs/ext-all-debug.js:109888:33)
at null.<anonymous> (http://ilmcon/js/desktop/app/view/grids/filterGrid.js?_dc=1388407912294:236:40)
at Object.Ext.Array.each (http://ilmcon/js/resources/extjs/ext-all-debug.js:1396:28)
at null.<anonymous> (http://ilmcon/js/desktop/app/view/grids/filterGrid.js?_dc=1388407912294:235:21)
at fire (http://ilmcon/js/resources/extjs/ext-all-debug.js:9818:49)
at continueFireEvent (http://ilmcon/js/resources/extjs/ext-all-debug.js:11210:47)
at fireEventArgs (http://ilmcon/js/resources/extjs/ext-all-debug.js:11188:26)


I really appreciated your help!

scottmartin
31 Dec 2013, 6:36 AM
What is your goal .. to have the columns auto-size based on the width of the grid, or to have to columns size based on the content of the field.

For the grid size, simply assign flex value to each column. If you want to change the size based on content, you can use autoSizeColumn() // same as expandToFit() in 4.1