Flex DataGrid 列宽

发布于 2024-08-02 12:44:58 字数 478 浏览 3 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

臻嫒无言 2024-08-09 12:44:58

在类文件顶部添加导入语句:

import mx.core.mx_internal;

然后使用 mx_internal 命名空间删除,删除列的所有者,更改宽度,然后重新分配父级:

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;
    }

这应该可以解决问题(好吧,在咒骂几天后,它为我们做到了)

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)

笑忘罢 2024-08-09 12:44:58

您是否在数据网格上将horizo​​ntalScrollPolicy 设置为 false ?

“如果 DataGrid 的 Horizo​​ntalScrollPolicy 属性为 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

违心° 2024-08-09 12:44:58

我能够通过在函数中调用上述循环两次来使其工作......第一次添加可见列,第二次设置正确的宽度。这不是最好的解决方案,但我不能再花时间了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文