显示时调整 DataGrid 大小

发布于 2024-11-08 19:19:02 字数 1200 浏览 2 评论 0原文

我正在尝试编写我的 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 技术交流群。

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

发布评论

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

评论(2

杯别 2024-11-15 19:19:02

一些想法:

  • 在 CreationComplete() 期间调整大小:您的数据网格何时创建?当数据网格的 creationComplete() 事件触发时,您可以声明像 resizeDataGrid() 这样的方法吗?如果您在 TabNavigator 中使用数据网格,则默认创建策略是延迟组件创建,直到用户使用该组件(例如,使选项卡处于活动状态)。
  • 固定大小:您的数据网格使用固定大小还是相对大小? Flex 中数据网格或数据网格列的相对大小(例如 width='50%')存在问题,最好的解决方法是设置数据网格和数据网格列的像素宽度
  • 存储用户首选项 :您如何存储您的用户偏好?使用 SharedObject 来存储数据网格宽度可能是最好的选择。
  • Spark 容器:数据网格是如何包含的?例如,它们是否都位于 VGroup 中,或者根本不包含在 VGroup 中?我发现使用 Spark 布局工具(如 VGroup)来包含数据网格可以改善数据网格布局问题。

A couple thoughts:

  • Resize during CreationComplete(): When are your datagrids being created? Can you declare a method like resizeDataGrid() when the 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).
  • Fixed Sizes: Are your datagrids using a fixed size, or a relative size? Relative sizing (e.g. width='50%') of a datagrid or datagrid columns is buggy in Flex, and the best workaround is to set a pixel width of both the datagrid and the datagrid columns
  • Storing User Preferences: How are you storing your user preferences? Using a SharedObject to store datagrid widths is probably the best option.
  • Spark Containers: How are the datagrids contained? For example, do they each sit within a VGroup, or are they not contained at all? I've found that using Spark layout tools (like a VGroup) to contain your datagrids improves datagrid layout issues.
谁与争疯 2024-11-15 19:19:02

我们所做的是在初始化时保存列宽度,然后在网格重新渲染时重置宽度,这将在第一次绘制网格和随后调整大小时发生。
唯一的问题是它需要调整列的大小,但不允许用户调整大小

// saves column width - this is intended to save width percent which
// will only be available on initialization, after that I beleive widths
// will be fixed size
private function saveOffColumnWidths(columns:ArrayCollection):void
{
    for each(var column:TDMSEDataGridColumn in columns)
    {
    originalColWidths.push(column.width);       
    }
}

// resets the column widths - the saved widths are assumed to be width percentages
private function resetColumnWidths():void
{
    dataGrid.columns[0].width=20; // set the check col seperately
    for (var pos:int=0; pos<dataGrid.columnCount-1;pos++ )
    {
    dataGrid.columns[pos+1].width = (dataGrid.width - 20) * originalColWidths[pos];
    }
} 

protected function dataGrid_renderHandler(event:Event):void
{
    resetColumnWidths();
}

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

// saves column width - this is intended to save width percent which
// will only be available on initialization, after that I beleive widths
// will be fixed size
private function saveOffColumnWidths(columns:ArrayCollection):void
{
    for each(var column:TDMSEDataGridColumn in columns)
    {
    originalColWidths.push(column.width);       
    }
}

// resets the column widths - the saved widths are assumed to be width percentages
private function resetColumnWidths():void
{
    dataGrid.columns[0].width=20; // set the check col seperately
    for (var pos:int=0; pos<dataGrid.columnCount-1;pos++ )
    {
    dataGrid.columns[pos+1].width = (dataGrid.width - 20) * originalColWidths[pos];
    }
} 

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