无法在 flex 数据网格中动态更改列宽 [英] Unable to change the column width dynamically in flex datagrid

查看:29
本文介绍了无法在 flex 数据网格中动态更改列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这非常非常令人沮丧.我正在使用包含数据网格的单例类(弹出窗口,这意味着它不会忘记上次使用的变量).我正在使各种列可见/不可见,根据从数据库调用接收到的数据设置宽度和标题.一切正常,除了当我在更改列宽的点之前和之后放置断点时,我根本看不到数据网格宽度的变化!相反,我看到一些值与 datagrid 列的宽度完全不同步!然而,由于它是一个单例类,下次我调用这个弹出窗口时,我会看到我在上次调用中设置的宽度.

It's very very frustrating. I am using a singleton class (popup, which means it doesn't forget the last used variables) which contains a datagrid. I am making various columns visible/invisible, setting the widths and headers in accordance to data received from a database call. Everything works fine except that when I put the breakpoints before and after the point where I change width of columns, I do not see the change in width of datagrid at all! Instead I see some values totally out of sync as widths of datagrid column! However, since it is a singleton class, the next time I call this popup, I see widths which I did set up in last call.

我一定是在调用 setWidth() 函数(这是我的自定义函数,它在动作脚本中更改数据网格的宽度)时搞砸了.我应该调用这个函数的重点是什么?我在creationComplete、show和dataprovider的setter中尝试过.没用...

I must be messing up in calling the setWidth() function (which is my custom function which changes the width of datagrid in action script). What should be the point where I should call this function? I tried in creationComplete, show and in the setter of dataprovider. Doesn't help...

我将水平滚动策略保持为关闭"(打开它会完全搞砸).

I have kept horizontal scroll policy as 'off' (turning it on totally messes it up).

如果我执行 datagrid.validateNow(),它没有帮助!如果我在更改前后放置断点,为什么我看不到宽度更改立即反映出来.有人请告诉我我在这里做错了什么.

If I do datagrid.validateNow(), it doesn't help! And why the hell I don't see the width change reflected immediately if I put the breakpoints before and after the change. Somebody please advise me about what I am doing wrong here.

谢谢.

推荐答案

首先,您要指出这里可能存在的问题.

First of all you are indicating yourself what might be wrong here.

1) 当组件可见时更新宽度 => 没有变化

1) When you update the width when the component is visible => no change

2) 当您关闭弹出窗口并重新打开它时,这没问题,这也意味着该项目已被重新渲染,而这不是第一次.这意味着您确实必须自己尝试触发此操作.

2) When you close the popup and reopen this it is ok, this also means that the item has been re-rendered whereas it was not the first time. This means that you indeed have to try and trigger this yourself.

这里有一些关于 flex 组件生命周期的有用链接.这些应该可以帮助您确定要调用和/或覆盖哪些方法.

Here are some usefull links concerning flex component lifecycle. These should help you figure out which methods to call and / or override.

http://weblog.mrinalwadhwa.com/2009/06/21/flex-4-component-lifecycle/

http://www.slideshare.net/rjowen/adobe-flex-component-lifecycle-presentation

此外,永远不要直接调用validateNow(),而应使用失效方法.

Furthermore, you should never call validateNow() directly, but use invalidation methods instead.

我想在这种情况下,您需要触发组件的测量,以便调用invalidateSize() 应该没问题.

I guess in this case you need to trigger the measurement of your component so a call to invalidateSize() should do just fine.

干杯

这篇关于无法在 flex 数据网格中动态更改列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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