0
votes

The following code is working:

item renderer:

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
    super.updateDisplayList(unscaledWidth, unscaledHeight);
    if(editMode)
        dispatchEvent(new Event("editLayoutChange"));
}

Datagrid (event handler function for "editLayoutChange" - "viewport" is the AdvancedDataGrid):

public function editLayoutChange(event : Event) : void {
    var viewportTopLeft : Point = viewport.localToGlobal(new Point(0,0));
    var viewportBottom : Number = viewportTopLeft.y + viewport.height;
    var rendererTopLeft : Point = Container(event.target).localToGlobal(new Point(0,0));
    var rendererBottom : Number = rendererTopLeft.y + Container(event.target).getLayoutBoundsHeight();

    var offset : Number = rendererBottom - viewportBottom; 

    if(offset > 0) {
        // Typical item height is 21px
        var itemHeight : Number = 21;
        matrix.verticalScrollPosition += Math.ceil(offset / itemHeight);
    } 
}

But I'm not sure that overriding updateDisplayList is the cleanest implementation as it's firing quite a bit. I tried dispatching the "editLayoutChange" event in response to the "resize" event on the item renderer, but I'm seeing really erratic behavior. Is there a better choice for dispatching this event than updateDisplayList?

Edit - I'm listening on updateDisplayList because the renderer will change size (grow) when it enters edit mode, and can expand dynamically during editing.

2

2 Answers

0
votes

The usual way to do this kind of thing is to dispatch from commitProperties -

In your renderer:

private var _editModeEntered:Boolean = false;

private var _editMode:Boolean;
public function set editMode(value:Boolean):void {
    _editMode = true;
    _editModeEntered = true;
    invalidateProperties();
}
// probably want a getter for editMode too

override protected function commitProperties():void {
    super.commitProperties();
    if (_enteredEditMode) {
        dispatchEvent(new Event("editLayoutChange"));
        _enteredEditMode = false;
    }
}

This ensures the event is dispatched only when you have changed editMode explictly.

0
votes

You can use Advanced Data Grid public API scrollToIndex(index) to scroll to the row