[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 708
  • Last Modified:

handle dataGrid update in a flex dataGrid

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 ){
            		
            		ReCalulate();	   
            	 }
            }

Open in new window

0
sidwelle
Asked:
sidwelle
  • 2
1 Solution
 
vindys80Commented:
Hi,

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="http://www.adobe.com/2006/mxml" layout="absolute"
	backgroundColor="#FFFFFF" creationComplete="init()"
	backgroundGradientAlphas="[1.0, 1.0]" 
	backgroundGradientColors="[#FFFFFF, #FFFFFF]">
	
	<mx:Script>
	<![CDATA[
		import mx.events.DataGridEvent;
		import mx.events.CollectionEventKind;
		import mx.events.CollectionEvent;
		import mx.events.FlexEvent;
		import mx.collections.ArrayCollection;
		private function init():void{
			inventoryDB.addEventListener(CollectionEvent.COLLECTION_CHANGE,collectionEventHandler);
			changedCell = new Object();
		}
		public function collectionEventHandler(event:CollectionEvent):void 
        {
            switch(event.kind) 
            {

                case CollectionEventKind.ADD:
                    addLog("Item "+ event.location + " added");
                    break;
                case CollectionEventKind.REMOVE:

                    addLog("Item "+ event.location + " removed");
                    break;
                case CollectionEventKind.REPLACE:

                    addLog("Item "+ event.location + " Replaced");
                    break;
                case CollectionEventKind.UPDATE:

                    addLog("Item updated");
                    break;
            }
        }
        public function addLog(str:String):void 
        {
			if( !isSent ){
            	trace(str + "column " + changedCell.c+ "row " + changedCell.r);
            	isSent = true;
   			}
        }
		[Bindable]
		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 
		}
			  
	]]>
	</mx:Script>
	
	<!-- inventory: simple text editing -->
	
	<mx:DataGrid x="46" y="79" editable="true" dataProvider="{inventoryDB}" itemEditEnd="dataChanged(event)">
		<mx:columns>
			<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"/>
		</mx:columns>
	</mx:DataGrid>
	
	
</mx:Application>

Open in new window

0
 
sidwelleAuthor Commented:
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
0
 
vindys80Commented:
Thanks for accepting.
But if you just want to know current row and col in focus on data change, you can use itemEditEnd http://www.adobe.com/livedocs/flex/3/langref/mx/controls/DataGrid.html#event: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.

Regards,
Vindys
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now