Maybe you are confused about how to do lookups.
 
For an object: var obj:Object = { first_name: Alex, last_name: Harui,
zipCode: 94103};
 
You can:
 
trace(obj.zipCode);     // 94103
 
or
 
var s:String = "zipCode";
trace(obj[s]);    // 94103
 
but
 
trace(obj.s); // undefined, there is no property named "s" in the object
 
-Alex

________________________________

From: [email protected]
[mailto:[EMAIL PROTECTED] On Behalf Of xmrcivicboix
Sent: Wednesday, February 14, 2007 7:56 PM
To: [email protected]
Subject: [flexcomponents] Re: DataGrid filtering help



BTW, I know how to do it by using a switch() statement, but it would
make my code too long. Take a look.

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> " width="100%"
height="340">

<mx:Script>
<![CDATA[
import model.UserModelLocator;
import view.UserInfo;

[Bindable]
private var _userModel:UserModelLocator =
UserModelLocator.getInstance();

[Bindable]
private var filtersComboBox:Array = [{field:"Date Registered",
value:"date_registered"},
{field:"Email Address", value:"email"},
{field:"First Name", value:"first_name"},
{field:"Last Name", value:"last_name"},
{field:"City", value:"city"},
{field:"State", value:"state"},
{field:"ZIP Code", value:"zipcode"},
{field:"Gender", value:"gender"}];

private function filterGrid(): void
{
_userModel.userInfo.filterFunction = filterBy;
_userModel.userInfo.refresh();
}

private function filterBy(item:Object): Boolean
{
var isMatch:Boolean = false;

switch(filterList.selectedItem.value)
{
case "zipcode":
if (item.zipcode.toLowerCase().search(search.text.toLowerCase())
!= -1)
isMatch = true;
break;
case "date_registered":
if
(item.date_registered.toLowerCase().search(search.text.toLowerCase())
!= -1)
isMatch = true;
break;
case "email":
if (item.email.toLowerCase().search(search.text.toLowerCase())
!= -1)
isMatch = true;
break;
case "first_name":
if
(item.first_name.toLowerCase().search(search.text.toLowerCase()) != -1)
isMatch = true;
break;
case "last_name":
if
(item.last_name.toLowerCase().search(search.text.toLowerCase()) != -1)
isMatch = true;
break;
case "city":
if (item.city.toLowerCase().search(search.text.toLowerCase()) != -1)
isMatch = true;
break;
case "state":
if (item.state.toLowerCase().search(search.text.toLowerCase())
!= -1)
isMatch = true;
break;
case "gender":
if (item.gender.toLowerCase().search(search.text.toLowerCase())
!= -1)
isMatch = true;
break;
default:
break;
}

return isMatch;
}
]]>
</mx:Script>
<mx:Grid width="100%">
<mx:GridRow width="100%">
<mx:GridItem width="100%">
<mx:DataGrid id="userGrid" allowDragSelection="true"
dataProvider="{_userModel.userInfo}" width="100%" height="300">
<mx:columns>
<mx:DataGridColumn dataField="date_registered" headerText="Date
Registered" minWidth="140"/>
<mx:DataGridColumn dataField="email" headerText="Email Address"
minWidth="200"/>
<mx:DataGridColumn dataField="first_name" headerText="First
Name" minWidth="50"/>
<mx:DataGridColumn dataField="last_name" headerText="Last Name"
minWidth="90"/>
<mx:DataGridColumn dataField="address" headerText="Address"
minWidth="130"/>
<mx:DataGridColumn dataField="address2" headerText="Apt/Suite"
minWidth="50"/>
<mx:DataGridColumn dataField="city" headerText="City"
minWidth="60"/>
<mx:DataGridColumn dataField="state" headerText="State"
minWidth="30"/>
<mx:DataGridColumn dataField="zipcode" headerText="ZIP Code"
minWidth="30"/>
<mx:DataGridColumn dataField="birth_date" headerText="Date of
Birth" minWidth="50"/>
<mx:DataGridColumn dataField="gender" headerText="Gender"
minWidth="30"/>
<mx:DataGridColumn dataField="disney_optin" headerText="Disney
Optin" minWidth="60"/>
<mx:DataGridColumn dataField="weather_optin" headerText="Weather
Channel Optin" minWidth="60"/>
</mx:columns>
</mx:DataGrid>
</mx:GridItem>
</mx:GridRow>
<mx:GridRow width="100%">
<mx:GridItem width="100%" horizontalAlign="right">
<mx:ComboBox selectedIndex="6" 
dataProvider="{filtersComboBox}" 
labelField="field" 
id="filterList" 
fontSize="11" 
height="22"/>
<mx:TextInput width="200" height="20" fontSize="9"
change="filterGrid()" id="search"/>
</mx:GridItem>
</mx:GridRow>
</mx:Grid>
</mx:Canvas>

--- In [email protected]
<mailto:flexcomponents%40yahoogroups.com> , "xmrcivicboix"
<[EMAIL PROTECTED]> wrote:
>
> Also, it would be cool it Flex offers the eval() function like some
> other languages.
> 
> --- In [email protected]
<mailto:flexcomponents%40yahoogroups.com> , "xmrcivicboix"
> <xmrcivicboix@> wrote:
> >
> > item.zipcode exists because the DataGridColumn -> dataField has a
> > property of "zipcode". If I do item.zipcode, I'm able to search all
> > the zipcode. Take a look here:
> > 
> > https://crux.baker.edu/~thuynh01/flex/ModelLocator.swf
<https://crux.baker.edu/~thuynh01/flex/ModelLocator.swf> 
> > 
> > type in some number in the text input below the datagrid. What I'm
> > trying to do it have the ability to filter based on what the
ComboBox
> > value is.
> > 
> > --- In [email protected]
<mailto:flexcomponents%40yahoogroups.com> , "Alex Harui" <aharui@>
wrote:
> > >
> > > I would debug or trace out each subexpression.
> > > 
> > > 
> > > 
> > > I don't see how item.zipcode can exist.
> > > 
> > > 
> > > 
> > > -Alex
> > > 
> > > 
> > > 
> > > ________________________________
> > > 
> > > From: [email protected]
<mailto:flexcomponents%40yahoogroups.com> 
> > > [mailto:[email protected]
<mailto:flexcomponents%40yahoogroups.com> ] On Behalf Of xmrcivicboix
> > > Sent: Wednesday, February 14, 2007 3:49 PM
> > > To: [email protected]
<mailto:flexcomponents%40yahoogroups.com> 
> > > Subject: [flexcomponents] DataGrid filtering help
> > > 
> > > 
> > > 
> > > Hi guys, I have a problem that I don't know if it's possible to
do. I
> > > have a DataGrid, a ComboBox, and a Search input field. When I
select a
> > > value in the ComboBox I want the text I enter to filter by what I
> > > selected. Here is my code:
> > > 
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> 
> > > <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> >
" width="100%"
> > > height="340">
> > > 
> > > <mx:Script>
> > > <![CDATA[
> > > import model.UserModelLocator;
> > > import view.UserInfo;
> > > 
> > > [Bindable]
> > > private var _userModel:UserModelLocator =
> > > UserModelLocator.getInstance();
> > > 
> > > [Bindable]
> > > private var filtersComboBox:Array = [{field:"Date Registered",
> > > value:"date_registered"},
> > > {field:"Email Address", value:"email"},
> > > {field:"First Name", value:"first_name"},
> > > {field:"Last Name", value:"last_name"},
> > > {field:"City", value:"city"},
> > > {field:"State", value:"state"},
> > > {field:"ZIP Code", value:"zipcode"},
> > > {field:"Gender", value:"gender"},
> > > {field:"Disney Optin", value:"disney_optin"},
> > > {field:"Weather Channel Optin", value:"weather_optin"}];
> > > 
> > > private function filterGrid(): void
> > > {
> > > _userModel.userInfo.filterFunction = filterBy;
> > > _userModel.userInfo.refresh();
> > > trace(filterList.selectedItem.value);
> > > }
> > > 
> > > private function filterBy(item:Object): Boolean
> > > {
> > > var isMatch:Boolean = false;
> > > 
> > > /**** THIS IS WHERE I HAVE PROBLEM ****/
> > > /**** IF I USE
> > > "item.zipcode.toLowerCase().search(search.text.toLowerCase()) !=
-1"
> > > it works good ****/ 
> > > if
> > >
>
(item.(filterList.selectedItem.value).toLowerCase().search(search.text.t
> > > oLowerCase())
> > > != -1)
> > > {
> > > isMatch = true;
> > > }
> > > 
> > > return isMatch;
> > > }
> > > ]]>
> > > </mx:Script>
> > > <mx:Grid width="100%">
> > > <mx:GridRow width="100%">
> > > <mx:GridItem width="100%">
> > > <mx:DataGrid id="userGrid" allowDragSelection="true"
> > > dataProvider="{_userModel.userInfo}" width="100%" height="300">
> > > <mx:columns>
> > > <mx:DataGridColumn dataField="date_registered" headerText="Date
> > > Registered" minWidth="140"/>
> > > <mx:DataGridColumn dataField="email" headerText="Email Address"
> > > minWidth="200"/>
> > > <mx:DataGridColumn dataField="first_name" headerText="First
> > > Name" minWidth="50"/>
> > > <mx:DataGridColumn dataField="last_name" headerText="Last Name"
> > > minWidth="90"/>
> > > <mx:DataGridColumn dataField="address" headerText="Address"
> > > minWidth="130"/>
> > > <mx:DataGridColumn dataField="address2" headerText="Apt/Suite"
> > > minWidth="50"/>
> > > <mx:DataGridColumn dataField="city" headerText="City"
> > > minWidth="60"/>
> > > <mx:DataGridColumn dataField="state" headerText="State"
> > > minWidth="30"/>
> > > <mx:DataGridColumn dataField="zipcode" headerText="ZIP Code"
> > > minWidth="30"/>
> > > <mx:DataGridColumn dataField="birth_date" headerText="Date of
> > > Birth" minWidth="50"/>
> > > <mx:DataGridColumn dataField="gender" headerText="Gender"
> > > minWidth="30"/>
> > > <mx:DataGridColumn dataField="disney_optin" headerText="Disney
> > > Optin" minWidth="60"/>
> > > <mx:DataGridColumn dataField="weather_optin" headerText="Weather
> > > Channel Optin" minWidth="60"/>
> > > </mx:columns>
> > > </mx:DataGrid>
> > > </mx:GridItem>
> > > </mx:GridRow>
> > > <mx:GridRow width="100%">
> > > <mx:GridItem width="100%" horizontalAlign="right">
> > > <mx:ComboBox dataProvider="{filtersComboBox}" labelField="field"
> > > id="filterList" fontSize="11" height="22"/>
> > > <mx:TextInput width="200" height="20" fontSize="9"
> > > change="filterGrid()" id="search"/>
> > > </mx:GridItem>
> > > </mx:GridRow>
> > > </mx:Grid>
> > > </mx:Canvas>
> > >
> >
>



 

Reply via email to