handle dataGrid update in a flex dataGrid

Posted on 2010-01-08
Last Modified: 2013-11-11
If I handle and event from a ArrayCollection in a dataGrid, how do I determine what row and col are either current or have been updated ?

private function MyUpDateHandler(event:CollectionEvent):void {

            	if( event.kind == CollectionEventKind.UPDATE ){





Open in new window

Question by:sidwelle
    LVL 11

    Accepted Solution


    I don't think there is a direct option to get row or column information on CollectionEvent. Alternatively you can listen to itemEditEvent and register column and row info. So you will have the last edited row or column.

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="" layout="absolute"
    	backgroundColor="#FFFFFF" creationComplete="init()"
    	backgroundGradientAlphas="[1.0, 1.0]" 
    	backgroundGradientColors="[#FFFFFF, #FFFFFF]">
    		import mx.collections.ArrayCollection;
    		private function init():void{
    			changedCell = new Object();
    		public function collectionEventHandler(event:CollectionEvent):void 
                    case CollectionEventKind.ADD:
                        addLog("Item "+ event.location + " added");
                    case CollectionEventKind.REMOVE:
                        addLog("Item "+ event.location + " removed");
                    case CollectionEventKind.REPLACE:
                        addLog("Item "+ event.location + " Replaced");
                    case CollectionEventKind.UPDATE:
                        addLog("Item updated");
            public function addLog(str:String):void 
    			if( !isSent ){
                	trace(str + "column " + changedCell.c+ "row " + changedCell.r);
                	isSent = true;
    		private var inventoryDB:ArrayCollection = new ArrayCollection(
    			[ {product:"Widgets", part:"WDG-1000", inStock:true, quantity: 53},
    			  {product:"Gizmos", part:"GZM-850", inStock:false, quantity: 0},
    			  {product:"Thingys", part:"THG-4320", inStock:true, quantity: 120},
    			  {product:"Gadgets", part:"GAT-910", inStock:true, quantity: 4}
    		private var isSent:Boolean = true;
    		private var changedCell:Object;
    		private function dataChanged(event:DataGridEvent):void{
    			changedCell.c = event.columnIndex;
    			changedCell.r = event.rowIndex;
    			isSent = false 
    	<!-- inventory: simple text editing -->
    	<mx:DataGrid x="46" y="79" editable="true" dataProvider="{inventoryDB}" itemEditEnd="dataChanged(event)">
    			<mx:DataGridColumn headerText="Product" dataField="product"/>
    			<mx:DataGridColumn headerText="Part #" dataField="part"/>
    			<mx:DataGridColumn headerText="In Stock?" dataField="inStock"/>
    			<mx:DataGridColumn headerText="Quantity" dataField="quantity"/>

    Open in new window


    Author Closing Comment

    Thanks, Sorry I did not get back sooner, got behind at work.

    So, In summary.  If I have a dataGrid and I want to know the current row & col in focus, I have to listen and record all that stuff on my own
    LVL 11

    Expert Comment

    Thanks for accepting.
    But if you just want to know current row and col in focus on data change, you can use itemEditEnd But drawback with this event is that it will be dispatched on each cell edit. If you want to get notified only on whole row change, you can use ArrayCollectionEvent.


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
    While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
    The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
    The goal of the tutorial is to teach the user how to how to record live broadcast.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now