Flex DataGrid Column Width

折月煮酒 提交于 2019-11-30 19:17:47

问题


In my flex app I store the widths and visiblility of columns in an xml file. When the app loads it reads from the xml file and sets he columns values as applicable:

for(i = 0; i < columnsOrder.length; i++){
    newOrder[i] = myDG.columns[Number(columnsOrder[i]) - 1];
    newOrder[i].visible = (Number(columnsVisiblity[i]) == 1);
    newOrder[i].width = Number(columnsWidth[i]);
}
myDG.columns = newOrder;
myDG.invalidateList();

The problem appears to be setting the visibility (it sets the visible field correctly but messes up the width)... I've tried setting it after setting the width (outside of the loop) and before the loop as well. It resizes the columns properly if I don't do anything with the visibility.

Any ideas?


回答1:


Add an import statement at the top of your class file:

import mx.core.mx_internal;

Then remove using the mx_internal namespace, remove the owner of the column, change the width and then reasign the parent:

public static function resizeColumn(col:DataGridColumn, size:int):void
    {
        var owner:* = col.mx_internal::owner
        col.mx_internal::owner = null;

        col.width = size;

        col.mx_internal::owner = owner;
    }

This ought to do the trick (well, it did for us after a couple of days of swearing)




回答2:


Is you horizontalScrollPolicy set to false on the datagrid?

"If the DataGrid's horizontalScrollPolicy property is false, all visible columns must fit in the displayable area, and the DataGrid will not always honor the width of the columns if the total width of the columns is too small or too large for the displayable area."

http://livedocs.adobe.com/flex/3/langref/mx/controls/dataGridClasses/DataGridColumn.html#width




回答3:


I was able to get it to work by calling the above loop in a function twice... the first time it add the visible columns, the second time it sets the correct width. Not the best solution but I cannot spend any more time on it.



来源:https://stackoverflow.com/questions/1289934/flex-datagrid-column-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!