filtering an array collection using 2 or 3 textinputs

classic Classic list List threaded Threaded
31 messages Options
12
Reply | Threaded
Open this post in threaded view
|

filtering an array collection using 2 or 3 textinputs

ZIONIST
Hi guys, can some help me with a simple example of filtering an array collection using 2 or three text inputs? please i will be very grateful.

Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

ZIONIST
any help out there... am stuck.

Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

Andrew Wetmore-2
Wouldn't you have have two or three nested filtering functions? That is,
apply the first input's text in the first filter function to AC and add the
results to the AC1. Then apply the second input's text in the second filter
function that applies to AC1 and add them to AC2, and so on. A little bit
of a pain to build, but it should work without any noticeable delays.

a


On Mon, Mar 4, 2013 at 8:17 AM, ZIONIST <[hidden email]> wrote:

> **
>
>
> any help out there... am stuck.
>
>  
>



--
Andrew Wetmore

http://cottage14.blogspot.com/
http://portfolio.cottage14.com
https://sites.google.com/site/mvplaywrights/home
http://livefrom-studioa.com
Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

ZIONIST
Thanks Andrew, could you please show me how that's done by use of an example. I can only do it with one textinput but i want to use different parameters to filter the array collection.

Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

ZIONIST
In reply to this post by Andrew Wetmore-2
any help guys? am really stuck.

Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

Andrew Wetmore-2
I did a quick Google search on "array collection multiple filters" and came
up with several tutorials with examples. Here is one:
http://nwebb.co.uk/blog/?p=371


On Tue, Mar 5, 2013 at 12:21 AM, ZIONIST <[hidden email]> wrote:

> **
>
>
> any help guys? am really stuck.
>
>  
>



--
Andrew Wetmore

http://cottage14.blogspot.com/
http://portfolio.cottage14.com
https://sites.google.com/site/mvplaywrights/home
http://livefrom-studioa.com
Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

ZIONIST
Thanks, but am still having issues... i have just one textinput working and not perfectly. here is the code NB. i call keywordChangeHandler(event)on the change of the textinput

/******************* code to get Archives *****************************/
                        //[Bindable]
                        private var archiveAr:ArrayCollection=new ArrayCollection();
                       
                        /* [Bindable]
                        private var filteredAr:ArrayCollection = new ArrayCollection(archiveAr.toArray()); */
                       
                        [Bindable]
                        private var filteredAr:ArrayCollection=new ArrayCollection();
                       
                        private function archiveResult(event:ResultEvent):void
                        {
                                archiveAr=event.result as ArrayCollection;
                                //filteredAr=event.result as ArrayCollection;
                        }
                       
                        /******************* Start Filter Functions ***************************/
                       
                        private var keywordText:String="keywords";
                       
                       
                       
                        private function filterGrid():void
                        {
                                archiveAr.filterFunction=myFilterFunction;
                                archiveAr.refresh();
                               
                                for (var i:int=archiveAr.length - 1; i >= 0; i--)
                                {
                                        if (!filteredAr.contains(archiveAr[i]))
                                        {
                                                filteredAr.addItem(archiveAr[i]);
                                        }
                                }
                                for (i=filteredAr.length - 1; i >= 0; i--)
                                {
                                        if (!archiveAr.contains(filteredAr[i]))
                                        {
                                                filteredAr.removeItemAt(i);
                                        }
                                }
                        }
                       
                        private function filterReset():void
                        {
                               
                                archiveAr.filterFunction=null;
                                archiveAr.refresh();
                       
                        }
                       
                        private function myFilterFunction(item:Object):Boolean
                        {
                                return item[keywordText].match(new RegExp(generalSearch.text, 'i'));
                                //return item[keywordText].match(new RegExp("^"+generalSearch.text, 'i'));
                        }
                       
                        private function keywordChangeHandler(event:Event):void
                        {
                                if (generalSearch.text != '')
                                {
                                        filterGrid();
                                }
                                else
                                {
                                        filterReset()
                                }
                               
                        }

Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

doug31415
In reply to this post by ZIONIST
Can you give more details on what you are trying to do? Use text inputs
how?

Doug
On Mar 5, 2013 1:06 AM, "ZIONIST" <[hidden email]> wrote:

> **
>
>
> any help guys? am really stuck.
>
>  
>
Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

ZIONIST
i would like to use the textinputs to filter the array collection using different parameters.

Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

devchetu
In reply to this post by Andrew Wetmore-2
Hi,

Could I use multiple
filtering function with the datagrid?



________________________________
 From: Andrew Wetmore <[hidden email]>
To: [hidden email]
Sent: Monday, March 4, 2013 6:54 PM
Subject: Re: [flexcoders] Re: filtering an array collection using 2 or 3 textinputs
 

 
Wouldn't you have have two or three nested filtering functions? That is, apply the first input's text in the first filter function to AC and add the results to the AC1. Then apply the second input's text in the second filter function that applies to AC1 and add them to AC2, and so on. A little bit of a pain to build, but it should work without any noticeable delays.

a



On Mon, Mar 4, 2013 at 8:17 AM, ZIONIST <[hidden email]> wrote:

 

>any help out there... am stuck.
>
>


--
Andrew Wetmore

http://cottage14.blogspot.com/
http://portfolio.cottage14.com
https://sites.google.com/site/mvplaywrights/home
http://livefrom-studioa.com


 
Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

doug31415
In reply to this post by ZIONIST
You may want to look up applying dynamic filters to array collections,as
well as clearing them and applying multiple sort fields. Can't give you
better direction without s clearer idea of what exactly you are trying to do

Doug
On Mar 5, 2013 9:33 AM, "ZIONIST" <[hidden email]> wrote:

> **
>
>
> i would like to use the textinputs to filter the array collection using
> different parameters.
>
>  
>
Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

Alex Harui
In reply to this post by ZIONIST
Post the code that filters with one TextInput and maybe folks will help you adjust it for more than one.


On 3/5/13 6:32 AM, "ZIONIST" <[hidden email]> wrote:






i would like to use the textinputs to filter the array collection using different parameters.






--
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui
Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

ZIONIST
In reply to this post by devchetu
Alex, i have an arraycollection (archiveAr) which i would like to filter based on the following multiple parameters; Keywords, title and subject. i would like to use 3 textinputs to do this. one for keywords, another for title and the last one for subject. Now i can only use one textinput to filter based on keywords and would like to have all of them filter the array collection depending on the users choice. below is the code i have so far. someone please help.

/******************* code to get Archives *****************************/

                         //[Bindable]

                         private var archiveAr:ArrayCollection=new ArrayCollection();



                         /* [Bindable]

                         private var filteredAr:ArrayCollection = new

ArrayCollection(archiveAr.toArray()); */



                         [Bindable]

                         private var filteredAr:ArrayCollection=new ArrayCollection();



                         private function archiveResult(event:ResultEvent):void

                         {

                                 archiveAr=event.result as ArrayCollection;

                                 //filteredAr=event.result as ArrayCollection;

                         }



                         /******************* Start Filter Functions ***************************/



                         private var keywordText:String="keywords";







                         private function filterGrid():void

                         {

                                 archiveAr.filterFunction=myFilterFunction;

                                 archiveAr.refresh();



                                 for (var i:int=archiveAr.length - 1; i >= 0; i--)

                                 {

                                         if (!filteredAr.contains(archiveAr[i]))

                                         {

                                                 filteredAr.addItem(archiveAr[i]);

                                         }

                                 }

                                 for (i=filteredAr.length - 1; i >= 0; i--)

                                 {

                                         if (!archiveAr.contains(filteredAr[i]))

                                         {

                                                 filteredAr.removeItemAt(i);

                                         }

                                 }

                         }



                         private function filterReset():void

                         {



                                 archiveAr.filterFunction=null;

                                 archiveAr.refresh();



                         }



                         private function myFilterFunction(item:Object):Boolean

                         {

                                 return item[keywordText].match(new RegExp(generalSearch.text, 'i'));

                                 //return item[keywordText].match(new RegExp("^"+generalSearch.text, 'i'));

                         }



                         private function keywordChangeHandler(event:Event):void

                         {

                                 if (generalSearch.text != '')

                                 {

                                         filterGrid();

                                 }

                                 else

                                 {

                                         filterReset()

                                 }



                         }  

Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

Alex Harui
It looks like there is more work going on here than necessary.  There should be no need to loop through the filteredArr and add and remove things.  You should be able to set the source or list property of the filteredAr to the source, toArray or list of archiveAr and maybe apply the same filter.  It depends a bit on what you want to share, if anything.

Anyway, regarding the filter function, since you already are filtering based on generalSearch.text, I don’t see why you can’t add other logic to further test on someOtherTextField.text.


On 3/5/13 8:56 PM, "ZIONIST" <[hidden email]> wrote:






Alex, i have an arraycollection (archiveAr) which i would like to filter based on the following multiple parameters; Keywords, title and subject. i would like to use 3 textinputs to do this. one for keywords, another for title and the last one for subject. Now i can only use one textinput to filter based on keywords and would like to have all of them filter the array collection depending on the users choice. below is the code i have so far. someone please help.

/******************* code to get Archives *****************************/

 //[Bindable]

 private var archiveAr:ArrayCollection=new ArrayCollection();

 /* [Bindable]

 private var filteredAr:ArrayCollection = new

ArrayCollection(archiveAr.toArray()); */

 [Bindable]

 private var filteredAr:ArrayCollection=new ArrayCollection();

 private function archiveResult(event:ResultEvent):void

 {

 archiveAr=event.result as ArrayCollection;

 //filteredAr=event.result as ArrayCollection;

 }

 /******************* Start Filter Functions ***************************/

 private var keywordText:String="keywords";

 private function filterGrid():void

 {

 archiveAr.filterFunction=myFilterFunction;

 archiveAr.refresh();

 for (var i:int=archiveAr.length - 1; i >= 0; i--)

 {

 if (!filteredAr.contains(archiveAr[i]))

 {

 filteredAr.addItem(archiveAr[i]);

 }

 }

 for (i=filteredAr.length - 1; i >= 0; i--)

 {

 if (!archiveAr.contains(filteredAr[i]))

 {

 filteredAr.removeItemAt(i);

 }

 }

 }

 private function filterReset():void

 {

 archiveAr.filterFunction=null;

 archiveAr.refresh();

 }

 private function myFilterFunction(item:Object):Boolean

 {

 return item[keywordText].match(new RegExp(generalSearch.text, 'i'));

 //return item[keywordText].match(new RegExp("^"+generalSearch.text, 'i'));

 }

 private function keywordChangeHandler(event:Event):void

 {

 if (generalSearch.text != '')

 {

 filterGrid();

 }

 else

 {

 filterReset()

 }

 }






--
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui
Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

ZIONIST
Hi Alex, i apply the result of the filtered archiveAr to the second array collection so as to use the Itemschangeeffect thats all. The generalSearch textinput only search's based on keywords, so in the event there are so many records with the same keywords i would like to drill down more by searching on other parameters too.

Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

Alex Harui
I guess I don’t understand what problem you are having.  Your use of generalSearch.text looks right to me.  What happens when you try to add another TextInput?  What does your code look like and what goes wrong?


On 3/6/13 12:02 AM, "ZIONIST" <[hidden email]> wrote:






Hi Alex, i apply the result of the filtered archiveAr to the second array collection so as to use the Itemschangeeffect thats all. The generalSearch textinput only search's based on keywords, so in the event there are so many records with the same keywords i would like to drill down more by searching on other parameters too.






--
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui
Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

ZIONIST
hi when i try to apply the second search parameter, nothing gets filtered. here is my code. please advise.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                                layout="vertical"
                                creationComplete="init()">

        <mx:Script>
                <![CDATA[
                        import mx.rpc.events.ResultEvent;
                        import mx.controls.Alert;
                        import mx.managers.CursorManager;
                        import mx.collections.ArrayCollection;
                       
                        private function init():void
                        {
                               
                                archiveSvc.getDocs();
                       
                        }
                       
                        /******************* code to get Archives *****************************/
                        [Bindable]
                        private var archiveAr:ArrayCollection=new ArrayCollection();
                       
                        private function archiveResult(event:ResultEvent):void
                        {
                               
                                archiveAr=event.result as ArrayCollection;
                       
                        }
                       
                        /******************* Start Filter Functions ***************************/
                       
                        private var keywordText:String="keywords";
                        private var titleText:String="title";
                        private var subjectText:String="subject";
                       
                        private function filterGrid():void
                        {
                               
                                archiveAr.filterFunction=myFilterFunction;
                                archiveAr.refresh();
                       
                        }
                       
                        private function filterReset():void
                        {
                               
                                archiveAr.filterFunction=null;
                                archiveAr.refresh();
                       
                        }
                       
                        private function myFilterFunction(item:Object):Boolean
                        {
                               
                                //return item[keywordText].match(new RegExp(generalSearch.text, 'i'));
                                return (item[keywordText].match(new RegExp(generalSearch.text, 'i'))) && (item[titleText].match(new RegExp(titleSearch.text, 'i')));
                       
                        }
                       
                        private function keywordChangeHandler(event:Event):void
                        {
                               
                                if (generalSearch.text != '')
                                {
                                        filterGrid();
                                }
                                else
                                {
                                        filterReset()
                                }
                       
                        }
                       
                        private function titleChangeHandler(event:Event):void
                        {
                               
                                if (titleSearch.text != '')
                                {
                                        filterGrid();
                                }
                                else
                                {
                                        filterReset()
                                }
                       
                        }

                ]]>
        </mx:Script>

        <mx:RemoteObject id="archiveSvc"
                                         destination="ColdFusion"
                                         source="tilelistFilter.src.cfcs.crud"
                                         showBusyCursor="true"
                                         fault="CursorManager.removeBusyCursor();Alert.show(event.fault.message)">

                <mx:method name="getDocs"
                                   result="archiveResult(event)"/>

        </mx:RemoteObject>

        <mx:HBox>

                <mx:VBox horizontalAlign="center">
                        <mx:Label text="Keyword Search:"/>
                        <mx:TextInput id="generalSearch"
                                                  change="keywordChangeHandler(event)"/>
                </mx:VBox>

                <mx:VBox horizontalAlign="center">
                        <mx:Label text="Search By Title:"/>
                        <mx:TextInput id="titleSearch"/>
                </mx:VBox>

                <mx:VBox horizontalAlign="center">
                        <mx:Label text="Search By Subject:"/>
                        <mx:TextInput id="subjectSearch"/>
                </mx:VBox>

        </mx:HBox>

        <mx:TileList width="800"
                                 height="100%"
                                 dataProvider="{archiveAr}"
                                 itemRenderer="renderers.archiveRenders"/>

</mx:Application>


Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

Alex Harui
Are you sure you want to use && and not ||?


On 3/7/13 4:18 AM, "ZIONIST" <[hidden email]> wrote:






hi when i try to apply the second search parameter, nothing gets filtered. here is my code. please advise.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
creationComplete="init()">

<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import mx.managers.CursorManager;
import mx.collections.ArrayCollection;

private function init():void
{

archiveSvc.getDocs();

}

/******************* code to get Archives *****************************/
[Bindable]
private var archiveAr:ArrayCollection=new ArrayCollection();

private function archiveResult(event:ResultEvent):void
{

archiveAr=event.result as ArrayCollection;

}

/******************* Start Filter Functions ***************************/

private var keywordText:String="keywords";
private var titleText:String="title";
private var subjectText:String="subject";

private function filterGrid():void
{

archiveAr.filterFunction=myFilterFunction;
archiveAr.refresh();

}

private function filterReset():void
{

archiveAr.filterFunction=null;
archiveAr.refresh();

}

private function myFilterFunction(item:Object):Boolean
{

//return item[keywordText].match(new RegExp(generalSearch.text, 'i'));
return (item[keywordText].match(new RegExp(generalSearch.text, 'i'))) && (item[titleText].match(new RegExp(titleSearch.text, 'i')));

}

private function keywordChangeHandler(event:Event):void
{

if (generalSearch.text != '')
{
filterGrid();
}
else
{
filterReset()
}

}

private function titleChangeHandler(event:Event):void
{

if (titleSearch.text != '')
{
filterGrid();
}
else
{
filterReset()
}

}

]]>
</mx:Script>

<mx:RemoteObject id="archiveSvc"
 destination="ColdFusion"
 source="tilelistFilter.src.cfcs.crud"
 showBusyCursor="true"
 fault="CursorManager.removeBusyCursor();Alert.show(event.fault.message)">

<mx:method name="getDocs"
   result="archiveResult(event)"/>

</mx:RemoteObject>

<mx:HBox>

<mx:VBox horizontalAlign="center">
<mx:Label text="Keyword Search:"/>
<mx:TextInput id="generalSearch"
  change="keywordChangeHandler(event)"/>
</mx:VBox>

<mx:VBox horizontalAlign="center">
<mx:Label text="Search By Title:"/>
<mx:TextInput id="titleSearch"/>
</mx:VBox>

<mx:VBox horizontalAlign="center">
<mx:Label text="Search By Subject:"/>
<mx:TextInput id="subjectSearch"/>
</mx:VBox>

</mx:HBox>

<mx:TileList width="800"
 height="100%"
 dataProvider="{archiveAr}"
 itemRenderer="renderers.archiveRenders"/>

</mx:Application>






--
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui
Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

ZIONIST
tried that and it doesn't work

Reply | Threaded
Open this post in threaded view
|

Re: filtering an array collection using 2 or 3 textinputs

Alex Harui
Give us an example of what is in the text fields and what is in the item and which ones should  and shouldn’t get filtered out.


On 3/7/13 9:56 AM, "ZIONIST" <[hidden email]> wrote:






tried that and it doesn't work






--
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui
12