header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
flex
Points:0
Posts:0
Answered

4/30/2010 3:19:39 AM

Title: please its urgent


Hi, I have one tree and data grid....

I am getting name of tree nodes when i clicked on it..I want to filter the data grid items based on the tree node names which i am getting from tree on chance event..
can anyone help me in filtering the data.. I dont know how to write code for this..please give me solution..its very urgent...

Here is my code


private function tree_Click(event:Event):void{
				
				//assc=new XMLList(event.result.asociate);
				//getAsscHierarchy.send();
				var theData:String = ""
				if (event.currentTarget.selectedItem.@company) {
					theData =  event.currentTarget.selectedItem.@company;
				}
				t.text=theData;
			}

---
<mx:Tree height="418" id="tree" width="186" labelField="@company" labelFunction="tree_labelFunc"
							 change="tree_Click(event);"></mx:Tree>
					<mx:AdvancedDataGrid  id="asscGrid" width="244" height="416"> 
						<mx:groupedColumns>
							
							<mx:AdvancedDataGridColumnGroup headerText="Cash Refunds #  -  (A)" width="30">
								<mx:AdvancedDataGridColumn dataField="@number"  
														   headerText="#" width="30"/>
								<mx:AdvancedDataGridColumn dataField="@value1"  
														   headerText="value" width="30"/>	
							</mx:AdvancedDataGridColumnGroup>
							
							<mx:AdvancedDataGridColumnGroup headerText="Cash Refunds $  -  (A)" width="30">
								<mx:AdvancedDataGridColumn dataField="@number"  
														   headerText="#" width="30"/>
								<mx:AdvancedDataGridColumn  dataField="@value2"  
														   headerText="value" width="30"/>
								
							</mx:AdvancedDataGridColumnGroup>
							<mx:AdvancedDataGridColumn  dataField="@storename"  
														headerText="store" width="30"/>
							<mx:AdvancedDataGridColumn  dataField="@districtname"  
														headerText="district" width="30"/>
							<mx:AdvancedDataGridColumn  dataField="@regionname"  
														headerText="region" width="30"/>
							<mx:AdvancedDataGridColumn  dataField="@companyname"  
														headerText="company" width="30"/>
							</mx:groupedColumns>
					</mx:AdvancedDataGrid>

based on theData i have to filter the datagrid.. please help me in coding ...



1
Brad
Points: 750
Posts:0
Accepted Answer
4/30/2010 4:08:21 AM



check this example code below to filter the dataGrid in flex actionscript 3.0, I hope it clarify how to use filter, if you still have problem ping me back :)


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"	verticalAlign="middle"
				backgroundColor="white">
<mx:Script>
	<![CDATA[
		import mx.controls.dataGridClasses.DataGridColumn;
					
		private function processFilterFruit(item:Object):Boolean {
			return item.value == "Fruit";
		}
		private function processFilterVehicle(item:Object):Boolean {
			return item.value == "Vehicle";
		}
		protected function button1_clickHandler(event:MouseEvent):void
		{
			arrColl.filterFunction = processFilterFruit;
			arrColl.refresh();
		}
		protected function button2_clickHandler(event:MouseEvent):void
		{
			arrColl.filterFunction = processFilterVehicle;
			arrColl.refresh();
		}
		protected function button3_clickHandler(event:MouseEvent):void
		{
			arrColl.filterFunction = null;
			arrColl.refresh();
		}
	]]>
</mx:Script>

<mx:ArrayCollection id="arrColl">
	<mx:source>
		<mx:Array>
			<mx:Object name="Apple" value="Fruit" />
			<mx:Object name="Guavava" value="Fruit" />
			<mx:Object name="Orange" value="Fruit" />
			<mx:Object name="Car" value="Vehicle" />
			<mx:Object name="Banana" value="Fruit" />
			<mx:Object name="Jeep" value="Vehicle" />
			<mx:Object name="Truck" value="Vehicle" />
		</mx:Array>
	</mx:source>
</mx:ArrayCollection>

<mx:Panel status="{arrColl.length}/{arrColl.source.length} item(s)">
	<mx:DataGrid id="dataGrid" dataProvider="{arrColl}" verticalScrollPolicy="on">
		<mx:columns>
			<mx:DataGridColumn dataField="name" />
			<mx:DataGridColumn dataField="value"  />
		</mx:columns>
	</mx:DataGrid>
	<mx:ControlBar>
		<mx:Button label="Filter by Fruit" click="button1_clickHandler(event)"/>
		<mx:Button label="Filter by Vehicle" click="button2_clickHandler(event)"/>
		<mx:Button label="No filter" click="button3_clickHandler(event)"/>
	</mx:ControlBar>
</mx:Panel>
</mx:Application>


2
flex
Points: 0
Posts:0
5/12/2010 11:51:56 PM



Hi,
Yes u have sent the code long before.. i tried that also..
but now what problem im facing is,
once i click first combobox it ll get filtered in forst column of grid.. after that if i click second combobox it should filter the data in already filterer datagrid contents...(in second column filter)
But that is not hapeening.. second column grid get filtered in default grid value only..but i dont want that..
Can u please suggest solution for this?

3
Brad
Points: 750
Posts:0
5/13/2010 3:05:58 AM



you can filter by any column , I have filtered the using "value" column , you can also filter by "name" column using code:

return item.name == "Apple";

4
member
Points: 0
Posts:0
5/13/2010 3:45:47 AM



Hi,

see if its my first state of grid.In this simple example it may feel odd..but whatever im developing such case will come..

Apple Fruit
Guavava Fruit
Orange Fruit
Orange Fruit
Apple Fruit
Apple Vehicle


when i click on filter by fruit i ll get o/p like


Apple Fruit
Guavava Fruit
Orange Fruit
Orange Fruit
Apple Fruit

which is proper..


now when i ckick on search by apple ( used like this return item.name == "Apple"; )

im getting o/p like,
Apple Fruit
Apple Fruit
Apple Vehicle



but it should not happen..it should only give

Apple Fruit
Apple Fruit

because i have already filtered based on fruits, now i wanna filter another column in this filtered items itself..

Can u please give solution for this..im struck in this from 1 week:( im facing problem in achiving this..


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 8+4 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions