0

以下代码正在工作:

项目渲染器:

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

Datagrid(“editLayoutChange”的事件处理函数 - “viewport”是 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);
    } 
}

但是我不确定覆盖 updateDisplayList 是最干净的实现,因为它会触发很多。我尝试调度“editLayoutChange”事件以响应项目渲染器上的“resize”事件,但我看到了非常不稳定的行为。调度此事件是否有比 updateDisplayList 更好的选择?

编辑 - 我正在监听 updateDisplayList 因为渲染器在进入编辑模式时会改变大小(增长),并且可以在编辑期间动态扩展。

4

2 回答 2

0

您可以使用 Advanced Data Grid 公共 APIscrollToIndex(index)滚动到该行

于 2015-01-13T12:42:17.907 回答
0

做这种事情的通常方法是从commitProperties-

在您的渲染器中:

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;
    }
}

这可确保仅在您明确更改时才调度事件editMode

于 2013-07-25T16:15:45.407 回答