2010-02-27 69 views
2

我有flex advancedDataGrid(如果工作得更好,可以使用dataGrid,儘管我喜歡我的元列標題),並且我希望在頂部有一個組件彈出窗口一個選定的行。在Flex中查找datagrid/adavancedDataGrid行的x,y位置

問題是,我可以弄清楚如何引用datagrid的實際渲染行(而不是數據提供者的項),以獲得它在屏幕上的位置。

有沒有人有任何關於如何訪問數據網格的「行」的理論,或至少得到它的立場?

乾杯

回答

1

我們最終在引用父文檔的itemrender中執行此操作。基本上,單擊時,項目渲染器會在父引用中引用一個函數。

在這一點上我們的父文檔知道選擇哪一個小區,我們做了一些處理,以確定其X,Y座標:

public function showPopup(selectedItemRenderer:UIComponent):void { 
     selectedCell = selectedItemRenderer; 

     PopUpManager.removePopUp(editPopup); 

     editPopup.height = dg.rowHeight; 

     BindingUtils.bindProperty(editPopup, "width", dg, "width"); 

     editPopup.setStyle("backgroundColor", 0xFF0000); 
     if(selectedCell != null) { 
      editPopup.x = selectedCell.localToGlobal(new Point(0,0)).x - 1; 
      editPopup.y = selectedCell.localToGlobal(new Point(0,0)).y - 1; 
     } 

     PopUpManager.addPopUp(editPopup, DisplayObject(Application.application)); 

    } 

<mx:DataGrid id="dg" width="500" height="100%" 
    dataProvider="{dummyData2}"> 
<mx:columns>   
    <mx:DataGridColumn 
     width="60"> 
     <mx:itemRenderer> 
      <mx:Component> 
       <mx:HBox> 
        <mx:Button label="edit" click="{parentDocument.showPopup(this)}" /> 
       </mx:HBox>       
      </mx:Component> 
     </mx:itemRenderer> 
    </mx:DataGridColumn> 
    <mx:DataGridColumn 
     dataField="Category"> 
    </mx:DataGridColumn>  
</mx:columns> 

0

最簡單的方式來獲得X,DataGrid的y位置是包裝在畫布裏面的DataGrid和嘗試捕捉mouseX和帆布mouseY的。如有必要,您可以使用localToGlobal方法。

1

我用dataGridColumn中的width屬性,只需將寬度加在一起即可獲得x位置,但問題在於當您使用lockColumnCount時,我的程序無法正確計算出x。