Flex DataGrid column width: one column to rule them all?

老子叫甜甜 提交于 2019-12-08 12:01:17

问题


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?


回答1:


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.




回答2:


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:


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



来源:https://stackoverflow.com/questions/4195445/flex-datagrid-column-width-one-column-to-rule-them-all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!