2 Replies Latest reply on Jun 19, 2008 3:57 PM by VarioPegged

    Checkbox Filtering a DataGrid - Hot damn!

    Blasem
      Hey everyone,

      I'm trying to filter a datagrid using checkboxes. The checkboxes represent common attributes of the products that load.

      For example, "wireless" or "corded" or "gaming" headsets.

      The heart and soul of my app work. I just need some assistance with best practice for building my xml schema and filtering the attributes properly.

      //====================================================

      The XML provided by the client looks like this__

      //====================================================

      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <products xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance">
      <item>
      <productname>Plantronics Bluetooth Voyager 510SL</productname>
      <corded>no</corded>
      <mobile>yes</mobile>
      <computer>no</computer>
      <dualuse>yes</dualuse>
      <noisecancelling>no</noisecancelling>
      <remote>yes</remote>
      <headband>no</headband>
      <behindhead>no</behindhead>
      <earbud>yes</earbud>
      <convertable>no</convertable>
      <singleear>yes</singleear>
      </item>
      <item>
      <productname>Plantronics Bluetooth Voyager 510SL+</productname>
      <corded>no</corded>
      <mobile>yes</mobile>
      <computer>no</computer>
      <dualuse>yes</dualuse>
      <noisecancelling>no</noisecancelling>
      <remote>yes</remote>
      <headband>no</headband>
      <behindhead>no</behindhead>
      <earbud>yes</earbud>
      <convertable>no</convertable>
      <singleear>yes</singleear>
      </item>
      </products>

      //====================================================

      The XML that I've been testing with looks like this__

      //====================================================

      <?xml version="1.0" encoding="UTF-8" ?>
      <products>
      <item>
      <productname>Plantronics Bluetooth Voyager 510SL</productname>
      <attributes>wireless,office</attributes>
      </item>
      <item>
      <productname>Plantronics Bluetooth Voyager 510SL+</productname>
      <attributes>wireless</attributes>
      </item>
      <item>
      <productname>Plantronics Bluetooth Voyager 510S</productname>
      <attributes>office,corded</attributes>
      </item>
      <item>
      <productname>Plantronics Bluetooth Voyager 510</productname>
      <attributes>corded</attributes>
      </item>
      <item>
      <productname>Jabra JX10 Series II w/Bluetooth Hub</productname>
      <attributes>corded,office</attributes>
      </item>
      <item>
      <productname>New Product A</productname>
      <attributes>wireless,office,corded</attributes>
      </item>
      <item>
      <productname>New Product B</productname>
      <attributes>wireless,corded,office</attributes>
      </item>
      </products>


      //====================================================

      My attached code works reasonably well with my testing XML. There's an issue when it comes to matching the attributes on "New Product B" depending on the order of the attributes. Obviously I've still got a ways to go.

      It took me a while just to get this far and I'm fading. Any advice on building the XML schema? Any thoughts on the filtering process? Perhaps I need to compare arrays to arrays...?

      Help please :)

      J
        • 1. Checkbox Filtering a DataGrid - Hot damn!
          VarioPegged Level 2
          First off, I'm not responding because I'm a genius :-)

          The schema chosen can make it easier to work with or it can make things unnecessarily hard. What I'm suggesting below is one of many different ways to do this, but if you can, use a schema where the elements themselves are the check box values, then everything is simplified in your code. You won't have to keep track of a ton of stuff, especially the correct order as you found out with New Product B.

          Note that you could also do <attributes wireless="true" office="true" corded="false" />, etc. Then you'd refer to it in your code as item.attributes["@" + i.id].

          TS
          • 2. Checkbox Filtering a DataGrid - Hot damn!
            VarioPegged Level 2
            Just want to add that you could probably set the hard-coded tempObj once in an init() handler. Then instead of resetting all 3 checkboxes each time add a call to a function that'll set the 'selected' property based on the event.currentTarget...

            <mx:CheckBox ..... click="filterCheckbox(event);"/>

            private function filterCheckbox(event:Event):void{
            setCheckBox(event);
            myData.filterFunction = searchCheckboxB;
            ....
            }

            private function setCheckBox(event:Event):void {
            tempObj[event.currentTarget.id].selected = event.currentTarget.selected;
            }

            TS