显示时调整 DataGrid 大小
我正在尝试编写我的 Flex 应用程序,以便它在启动时恢复用户的设置。该应用程序有 3 个数据网格(任何时候只有一个在屏幕上可见),如果用户执行任何大小调整事件,我只需保存网格的状态。
保存状态工作正常,恢复时出现问题。似乎只有可见的数据网格才能正确恢复。在所有其他网格上,宽度都是错误的,并且与我恢复的设置不匹配。
问题在于,当应用程序启动时,数据网格的大小不正确。每个数据网格占据全屏,但最初它们只被赋予非常小的尺寸(即200宽度)
是否有某种方法可以强制数据网格在创建时正确调整大小?或者是否有可能知道数据网格何时“最大化”,我不想连接到调整大小事件 - 如果可能的话 - 因为我会经常得到这个事件,并且我只想恢复设置一次。
这是我用来恢复列宽的代码:
var grid:DataGrid = ...;
... for each column ...
... parse width into width (ie. width is now "320")
// If it's in the config, it's visible
col.visible = true;
col.width = width;
... After loop ...
grid.invalidateSize();
grid.invalidateDisplayList();
编辑:
这是你们请求的信息:
设置保存到数据库中(flex 项目连接到 JBoss)。我只是保存一个 CSV 类型的内容以及列的名称和宽度。我知道这是可行的,因为应用程序启动时可见的一个数据网格的大小正确。
是的,网格使用相对大小(即 100%)——我无法真正改变它,因为我希望网格占据其容器中的所有可用空间——并且我希望用户能够调整浏览器大小,但仍然看起来正确。
每个网格都包含在自己的 Hbox 中
数据网格是在应用程序启动时创建的 - 但您只能看到其中一个。它们位于选项卡导航器类型的东西中,但它的创建策略设置为“全部”,以便它们可以填充数据(填充需要一些时间,通常用户会在前面的网格上坐一会儿。)
我无法将调整大小的内容放入creationComplete 处理程序中,因为我最终遇到了同样的问题。网格的大小在创建后大约是 50(应该是 1000,页面宽度的 100%)——然后我去设置列的大小(显然 > 50)并且调整大小没有任何作用
I'm trying to write my flex application so that it restores the user's settings when it starts up. The application has 3 data grids (only one is visible [on screen] at any time) and I simply save the state of the grids if the user ever does any resize events.
Saving the state works perfectly, the problem comes when restoring. It seems that only the visible data grid gets restored properly. On all the other grids, the widths are all wrong and do not match the settings I restored from.
The problem is that, when the application starts, the data grids are not sized correctly. Each data grid takes up the full screen, but initially they are only given a very small size (ie. 200 width)
Is there some way to force the data grid to resize properly when it is created? Or is it possible to know when the data grid is "maximized" I don't want to hook up to the resize event - if possible - because I would get that quite frequently, and I only want to restore the settings once.
Here's the code I'm using to restore the column widths:
var grid:DataGrid = ...;
... for each column ...
... parse width into width (ie. width is now "320")
// If it's in the config, it's visible
col.visible = true;
col.width = width;
... After loop ...
grid.invalidateSize();
grid.invalidateDisplayList();
Edit:
Here's the info you guys requested:
The settings are saved into a database (the flex proejct is connected to JBoss). I simply save a CSV type thing with the column's name and it's width. I know this works because the one data grid that is visible when the application starts gets sized correctly.
Yes, the grids use relative sizes (ie. 100%) -- I can't really change that because I want the grid to take up all available space in its container -- and I want the user to be able to resize their browser and still have it look right.
Each grid is contained in its own Hbox
The data grids are created when the application starts -- you can only see one of them though. They are in a tab navigator type thing, but it's creation policy is set to "all" so they can be populated with data (the population takes some time, and typically the user sits on the front grid for a little while.)
I can't put my resize stuff in the creationComplete handler because I end up with the same problem. The grid's size is like 50 right after it's created (it should be like 1000, 100% of the page width) -- and then I go to set the sizes of the columns (which are obviously > 50) and the resize does nothing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一些想法:
creationComplete()
事件触发时,您可以声明像 resizeDataGrid() 这样的方法吗?如果您在 TabNavigator 中使用数据网格,则默认创建策略是延迟组件创建,直到用户使用该组件(例如,使选项卡处于活动状态)。SharedObject
来存储数据网格宽度可能是最好的选择。A couple thoughts:
creationComplete()
event fires for the datagrid? If you are using datagrids in, say, a TabNavigator, the default creation policy is to delay component creation until the user uses the component (e.g. makes the tab active).SharedObject
to store datagrid widths is probably the best option.我们所做的是在初始化时保存列宽度,然后在网格重新渲染时重置宽度,这将在第一次绘制网格和随后调整大小时发生。
唯一的问题是它需要调整列的大小,但不允许用户调整大小
What we did was saved off the column width on initialization and then reset the widths on rerender of the grid, this will occur on the first draw of the grid and subsequent resizes.
the only problem with this was that it requires columns to be resizable but does not allow the user to resize