Flex 3 DataGrid column width issue

I am pulling in xml data to determine which columns are visible and the widths of each column. The datagrid width can change sinces on one side of the HDividedBox. Part of the visibility works, but setting the width causes headaches. Here is 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 elements, but it will always display as "20" consistent ...

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 is displayed as the correct value, so something weird happens when assigning the width.

Looked at this for hours and tried several things to try and fix it to no avail.

+2


source to share


4 answers


My datagrid width can change sinces on one side of HDividedBox.

This is the problem right there.



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

+3


source


I did the same in AdvancedDataGrid and it works. Try to set these values

  horizontalScrollPolicy="on"
  width="100%

      



and then add columns that should work with HDividedBox.

+1


source


You can do this, this is what I think is a bug in the DataGrid itself.

If you set minWidth = "0" and horizontalScrollPolicy = "{ScrollPolicy.AUTO}" in the DataGrid, you can then create fixed-width DataGridColumn objects and execute them correctly.

However, there is still a problem with the last column, when the DataGrid is still larger than the sum of all fixed widths, it will stretch the final output of the DataGridColumn.

You can get around this by adding an empty column at the end with no header, etc.

+1


source


Okay - we ran into this ourselves by creating support for different column width modes. Just a bit of a tidbit - if you want to explicitly set the width, make sure you do something like this:

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

      

+1


source







All Articles