Flex 3 DataGrid Column Width Problem

廉价感情. 提交于 2019-12-18 07:06:59

问题


I'm pulling xml data to determine which columns are visible, and the widths of each column. My datagrid's width can change sinces its on one side of a HDividedBox. The visibility part works, but setting the width is causing headaches. Heres the code:

for(loop through column data retrieve from XML)
{ 
    newData[i] = dg.columns[Number(columnsOrder[i]) - 1];
    newData[i].visible = (Number(columnsVisibility[i]) == 1);
    newData[i].width = Number(columnsWidth[i]);
    trace(newData[i].headerText + " w:" + newData[i].width.toString() + " v:" + newData[i].visible.toString());
}
dg.columns = newData;
dg.invalidateList();

In the trace the width is correct for the first two items, however, its showing up as "20" for ever consecutive one...

Date w:240 v:true
Title w:184 v:true
Requestor w:20 v:true
Approved By w:20 v:true
Category w:20 v:false
Status w:20 v:false
Priority w:20 v:false

When I output Number(columnsWidth[i]) it shows up as the correct value so something weird is happening in the assignment of the width.

Been looking at this for a few hours now, and have tried multiple things to try to fix it to no avail.


回答1:


My datagrid's width can change sinces its on one side of a HDividedBox.

That's the problem right there.

I faced the exact same problem with Flex 2 and Flex 3 DataGridColumn width's whenever the width for the DataGrid was not fixed. The only solution I had was to fix the width of the DataGrid or switch to AdvancedDataGrid or other similar components.




回答2:


I have done the same thing in AdvancedDataGrid and it works. Try by setting these values

  horizontalScrollPolicy="on"
  width="100%

and then add you columns this should work with HDividedBox.




回答3:


You can accomplish this, it's what I believe is a bug in the DataGrid itself.

If you set minWidth="0" and horizontalScrollPolicy="{ScrollPolicy.AUTO}" on the DataGrid, you can then create DataGridColumn Objects with fixed widths and have it be obeyed properly.

However, there seems to still be an issue with the final column, when the DataGrid is still larger then the sum of all of the fixed widths, it will stretch the final DataGridColumn out.

You could get around this by adding a blank column at the end with no header text etc.




回答4:


Ok - we've run into this ourselves while building support for various column width modes. Just a little tidbit of information - if you want to set widths explicitly, make sure you do something like this:

var oldPolicy:String = grid.horizontalScrollPolicy;
grid.horizontalScrollPolicy ="on"
//set your widths here
grid.horizontalScrollPolicy =oldPolicy;


来源:https://stackoverflow.com/questions/1302522/flex-3-datagrid-column-width-problem

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