views:

305

answers:

1

Hello!
I have some DataGrid with editable rows, which has also an option to add new row 'dynamically'. I mean, last row has some default data (e.g. "CLICK HERE TO ADD NEW ROW") and when user clicks on it, he can edit that value and new row will be eventually inserted.

However, I also have a column in same DataGrid which doesn't come from DataGrid's DataProvider. That column is used to delete specific row and it should only display clickable image with associated mouse click action (within custom itemRenderer).

I would like to display that image on every row except that last one.

Here is my DataGridColumn code so far:

<mx:DataGridColumn width="20" editable="false">
    <mx:itemRenderer>
        <mx:Component>
            <mx:VBox creationComplete="cc()">
                <mx:Script>
                    <![CDATA[
                        import mx.controls.Alert;
                        import mx.events.CloseEvent;

                        public function cc():void{
                            delImg.source = "assets/images/delete-icon.png";
                        }
                    ]]>
                </mx:Script>
                <mx:Image id="delImg" smoothBitmapContent="true" width="15" height="15" click="outerDocument.confirmDelete(event)"/>
            </mx:VBox>
        </mx:Component>
    </mx:itemRenderer>
</mx:DataGridColumn>

I suppose I should put some condition in my cc function and somehow compare current row's index or something with my dataProvider's length... I'm not really sure how to do that since I cannot get rowIndex property because I'm not working with DataGridEvent here...

Please help me with this one and thank you very much for any help! :)

+1  A: 

A VBox does not implement IDropInListItemRenderer. A IDropInListItemRenderer gives you the "listData" property (which is of type "DataGridListData"). Furthermore, "listData.owner" will be the DataGrid object, and "listData.rowIndex" gives you the rowIndex property.

Luis B
Another useful interface to implement for future thought when using itemRenderers is IDataRenderer, which gives you the "data" property; the data property represents the currentRow's object.You might want to implement something like this in your cc function:var grid1:DataGrid = DataGrid(DataGridListData(listData).owner);if (grid1.isItemSelected(data) || grid1.isItemHighlighted(data))return;
Luis B
Thank you very much for this useful and very helpful information ;-)
errata