Coming from Flex 3, if I wanted to set the size of my DataGrid columns to ensure that all of my data was displayed correctly, I would either set column widths with explicit values or percentages. In Flex 4, explicit width columns is no longer the recommended way of figuring out the size of columns according to Spark DataGrid’s architect Hans Muller who schooled me when I mentioned the need to fix a bug that involved explicit width columns.
By default, a DataGrid will use the first item in its dataProvider to determine the size of each column. This may not be what you want. If you specify a typicalItem on the DataGrid, the columns will be large enough to fit this item. This item does not need to be a part of your dataProvider.
Specifying explicit column widths can be problematic because the width can be invalidated by a host of factors: implicit renderer changes, e.g. due to inherited styles, explicit renderer changes, margin/padding and other layout configuration changes, as well as text and text format localizations. For all of these reasons, using the typicalItem is better.
In the following example, I have two DataGrids with the same data and columns. The first one specifies a typicalItem where the data includes the longest strings that I want to display in my columns. The second DataGrid uses no typicalItem and therefore sizes its columns using the first item of the dataProvider.
Sample application: TypicalItem_DataGrid_Example.swf
Sample MXML: TypicalItem_DataGrid_Example.mxml
If you change your typicalItem, you will need to call invalidateTypicalItem() notifying the DataGrid of this change.
Note, almost all of this information was compiled from picking the brain of Hans Muller, I hope I’ve accurately represented his thinking.