以下代码正在运行:
项目渲染器:
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"响应"调整大小"项目渲染器上的事件,但我看到了非常不稳定的行为。调度此事件比updateDisplayList更好吗?
编辑 - 我正在侦听updateDisplayList,因为渲染器在进入编辑模式时会改变大小(增长),并且可以在编辑过程中动态扩展。
答案 0 :(得分: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
时调度事件。
答案 1 :(得分:0)
您可以使用高级数据网格公共API scrollToIndex(index)
滚动到该行