7 Replies Latest reply on Mar 28, 2008 7:41 AM by EvolvedDSM

    Filter dataGrid from a List?

    EvolvedDSM Level 2
      i'm building an app that pulls data from an XML file. A List and a dataGrid are populated using their own arrayCollections. I would like to filter the dataGrid results when I choose an item from the List.
      XML file is set up like this:
      Basically there are users who have clients assigned to them. I have specified all the users in the XML file, and then I specify all the clients below it with the corresponding userID that it belongs to. A user can have an infinite # of clients.

      I first call the HttpService:
      <mx:HTTPService id="srv" url="agencydb.xml" result="readXML(event)"/>

      Then I create the arrayCollections and set them:
      private var clients:ArrayCollection = new ArrayCollection();
      private var names:ArrayCollection = new ArrayCollection();

      private function readXML(event:ResultEvent):void{
      The app begins with the List populating all the users using an arrayCollection:
      <mx:List id="nl" dataProvider="{names}" labelField="userName"/>

      Then I populate the dataGrid using the clients arrayCollection:
      <mx:DataGrid dataProvider="{clients}">
      <mx:DataGridColumn headerText="Client Name" dataField="clientName"/>
      <mx:DataGridColumn headerText="SSN" dataField="clientssn"/>

      When I start the app, the List and dataGrid both populate. The dataGrid has hundreds of clients though, and I wish to select a specific worker from my List to view only the clients that apply to said person. How do I go about doing this filter?
        • 1. Re: Filter dataGrid from a List?
          ntsiii Level 3
          Implement a change handler function on myList. In that function invoke the DG dataProvider ArrayCollection filter, using the appropriate property value in the myList.selectedItem object.

          • 2. Re: Filter dataGrid from a List?
            EvolvedDSM Level 2
            Ok, help me with this....
            I've added a change handler like so...
            <mx:List id="nl" dataProvider="{names}" labelField="userName" change="listFilter()"/>

            In my Script I've added....
            private function listFilter():void{
            clients.filterFunction = dgFilter; //clients is the dataProvider for the dg

            private function dgFilter(item:Object):Boolean{
            return item....?????;

            I don't know how to finish off the dgFilter function. =\
            • 3. Re: Filter dataGrid from a List?
              EvolvedDSM Level 2
              Nevermind, I figured it out.

              private function dgFilter(item:Object):Boolean{
              return (item.userID == nl.selectedItem.userID);

              I was trying item.userID == nl.selectedItem forever, and it kept giving me an error. Thanks fro the tip on the handler.
              • 4. Re: Filter dataGrid from a List?
                EvolvedDSM Level 2
                Ok, last question....

                If I want to add a comboBox or dateChooser to filter my dataGrid a second time (as in, I choose an item from the List and then make a selection from the comboBox or dateChooser to filter twice), how do I go about this in the Script?

                doing another array.filterFunction overwrites my first filterFunction. I need to add to the filterFunction is what I'm saying.
                • 5. Re: Filter dataGrid from a List?

                  I was going through ur question and i have another q to you if you could help me in that.
                  I am also creating the app which pulls the data from the XML. My application has to fetch the data from the database, create the xml and then load it to flex component.
                  I want to know if you also have to create the xml in ur application or you get it from somewhere else?
                  If you are creating the xml at your end, do you have any benchmark with you as to how much time it takes to create the xml for say 10000 records.

                  Also even if you are not creating the xml, and just feeding the xml to your application, how much time for a specific size of xml it takes to load/populate the datagrid at your end?
                  I am looking for some benchmarks to see usually what is the performance and how much time it takes the xml to populate the screen.

                  Any help would be appreciated.

                  • 6. Re: Filter dataGrid from a List?
                    ntsiii Level 3
                    I would declare two instance(global) vars, one for each of the two filter values, say:
                    private var _sFilterValUserId:String = "";
                    private var _sFilterValCategory:String = "";

                    Each change handler would set the value of the corresponding var.

                    then in the filter function, I would use those two instance var values to build my filter expression.
                    private function dgFilter(item:Object):Boolean{
                    if (sFilterValUserId.length > 0) {
                    if(sFilterValCategory.length > 0) {
                    return (item.userID == sFilterValUserId && item.category == sFilterValCategory);
                    else {
                    return (item.userID == sFilterValUserId);
                    else {
                    return true;

                    Get the idea?

                    • 7. Re: Filter dataGrid from a List?
                      EvolvedDSM Level 2
                      Tracy this worked better than I thought! +rep if I could! haha, thanks again