views:

20

answers:

2

I have an AdvancedDataGrid with a custom label function whose value can change based on other form status (specifically, there's a drop down to choose the time display format for some columns).

Right now, I have this labelFunction:

internal function formatColumnTime(item: Object, column: AdvancedDataGridColumn): String {
    var seconds: Number = item[column.dataField];
    return timeFormat.selectedItem.labelFunction(seconds);
}

internal function formatTimeAsInterval(time: Number): String {
    if (isNaN(time))
        return "";

    var integerTime: int = Math.round(time);

    var seconds: int = integerTime % 60;
    integerTime = integerTime / 60;
    var minutes: int = integerTime % 60;
    var hours: int = integerTime / 60;

    return printf("%02d:%02d:%02d", hours, minutes, seconds);
}

internal function formatTimeAsFractions(time: Number): String {
    if (isNaN(time))
        return "";

    var hours: Number = time / 3600.0;
    return new String(Math.round(hours * 100) / 100);
}

... and the timeFormat object is a combo box with items whose labelFunction attributes are formatTimeAsFractions and formatTimeAsInterval.

The columns that have time formats have formatColumnTime as their labelFunction value, because extracting the seconds in that function and passing it in to the formatters made for a more testable app (IMHO).

So, when the timeFormat.selectedItem value changes, I want to force my grid to re-calculate the labels of these colums. What method must I call on it? invalidateProperties() didn't work, so that's out.

A: 

Did you try refreshing the dataProvider? If it is an ArrayCollection, that should work. Otherwise try invalidateDisplayList().

Robusto
I could definitely do that, but there's a cost involved; it's a hierarchical grouping collection, which takes no small amount of time to perform all of the summary row calculations. I'd rather not rebuild the whole hierarchy just for that.
Chris R
Invalidating the display list should work for you. The way the AdvancedDataGrid works is it only refreshes the visible portion (what you see in the viewport) of the grid, but scrolling invalidates the displaylist anyway so all the offscreen data will be right as well.
Robusto
Nope, doesn't work; The change still doesn't take effect until I expand one of the grouped entries.I'm open to other ideas. I'd check the source, but `AdvancedDataGrid` is one of the ones for which the SDK doesn't provide source.
Chris R
A: 

I've gone the route of directly using the combo box's selectedItem as the labelFunction. It's not as elegantly testable, but it works.

Chris R