Flex DataGrid 列宽
在我的 Flex 应用程序中,我将列的宽度和可见性存储在 xml 文件中。当应用程序加载时,它从 xml 文件中读取并将列值设置为适用:
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();
问题似乎是设置可见性(它正确设置了可见字段,但弄乱了宽度)...我尝试在设置后设置它宽度(循环外部)以及循环之前的宽度。如果我不对可见性做任何事情,它会正确调整列的大小。
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在类文件顶部添加导入语句:
import mx.core.mx_internal;
然后使用 mx_internal 命名空间删除,删除列的所有者,更改宽度,然后重新分配父级:
这应该可以解决问题(好吧,在咒骂几天后,它为我们做到了)
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:
This ought to do the trick (well, it did for us after a couple of days of swearing)
您是否在数据网格上将horizontalScrollPolicy 设置为 false ?
“如果 DataGrid 的 HorizontalScrollPolicy 属性为 false,则所有可见列都必须适合可显示区域,并且如果列的总宽度对于可显示区域来说太小或太大,DataGrid 将不会始终遵循列的宽度。”
http://livedocs.adobe.com/ flex/3/langref/mx/controls/dataGridClasses/DataGridColumn.html#width
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
我能够通过在函数中调用上述循环两次来使其工作......第一次添加可见列,第二次设置正确的宽度。这不是最好的解决方案,但我不能再花时间了。
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.