Flex DataGrid column width: one column to rule the

2019-06-11 03:02发布

I have a Flex 4, mx:DataGrid with the following (pertinent) properties set:

width="100%"
horizontalScrollPolicy="off"

I have the minWidth set on all of the DataGridColumns and the width set on one of them. If I simply maximize/minimize the display (in browser or stand-alone flash player) of the application, the columns scale up and down nicely. But if you grab the edge of the application and drag it to make it bigger, only one column grows really big. When you drag the size down again, the one column remains big, but all of the other columns get squished way down.

Is this a bug in the Flex DataGrid, or am I just missing a key property (or properties on the datagrid columns) to set, to make all columns grow and shrink when you drag-enlarge the app?

3条回答
做个烂人
2楼-- · 2019-06-11 03:12

Solved this problem as follows:

in creationComplete add

{  
.....
grd_Principal.addEventListener(ResizeEvent.RESIZE, resizeGrid);
grd_Principal.dispatchEvent(new ResizeEvent(ResizeEvent.RESIZE));
...
}

protected function resizeGrid(event:ResizeEvent):void
{
    grd_Principal.horizontalScrollPolicy = 'on';                // datagrid
    ..... your DataGridColumn
    dgc_nCdId.width = grd_Principal.width * 0.06;               //datagridcolumn in percent
    dgc_Excluir.width = 20;                                                     //normal
    dgc_cNmUsuario.width = grd_Principal.width * 0.226;

    grd_Principal.horizontalScrollPolicy = 'off';               
}

查看更多
别忘想泡老子
3楼-- · 2019-06-11 03:23

Try capturing the event, setting the horizontalScrollPolicy to On, letting Flex resize the columns itself, then setting horizontalScrollPolicy back to Off

查看更多
Luminary・发光体
4楼-- · 2019-06-11 03:29

It is an unpleasant anomaly, if not an actual bug, in the way Flex does datagrids. In Adobe's defense, figuring out how to resize all the columns appears not to be a trivial task.

The way I've always handled this is to make a dummy column at the end, with a minWidth of 4 and no width specification. Then that becomes the "expandable column" that takes up the slack. Then I make sure to allow the rest of the columns enough room to display their data and their header renderers from the start by giving each a minWidth and a width. The only time I have problems is if there are too many columns to display in the space allowed, in which case you get a horizontal scrollbar and all (or most) bets are off.

查看更多
登录 后发表回答