Flex DataGrid 列宽 [英] Flex DataGrid Column Width

查看:45
本文介绍了Flex DataGrid 列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 flex 应用程序中,我将列的宽度和可见性存储在一个 xml 文件中.当应用加载时,它会从 xml 文件中读取数据并将列值设置为适用:

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.

有什么想法吗?

推荐答案

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

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

导入 mx.core.mx_internal;

import mx.core.mx_internal;

然后使用 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)

这篇关于Flex DataGrid 列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆