3 Replies Latest reply on Sep 5, 2007 12:27 PM by ntsiii

    Display a subset of data?

    Handycam Level 1
      I have a data grid populated by an XMLList from an XML file. Currently, it displays data from the entire file.

      However, there is a node for each item in the list indicating a category, e.g. "Fruits", Vegetables"

      I want to have a toggle button bar with buttons "Fruits", "Vegetables" that when clicked update the datagrid display to only show records matching the term.

      How is this done? The book I bought (Friends of Ed) only showed the solution usinf ColdFusion, but I need to do it all in Flex. Thanks.
        • 1. Re: Display a subset of data?
          I am not an expert but I have a set of radio buttons that need to filter data in a grid and I use a filter function like this;

          ----Where you load the datat associate a filter like this------


          ------ Here is the filter ---------

          public function grdVendorDetailFilter(item:Object):Boolean
          var result:Boolean=false;
          switch (rbtnStatus.selectedValue.toString().toUpperCase())
          case "ALL":
          case "CLEARED":
          if (item.CLEAR_DATE != null) result = true;
          case "UNCLEARED":
          if (item.CLEAR_DATE == null) result = true;
          return result;

          ---- In the clickevent of the radio button do this ------


          That is all there is to it...

          • 2. Re: Display a subset of data?
            batmitra Level 1
            i'm not sure about this but probably you can use the datagrid dataprovider to acomplish what you want , here's how :

            if you have an xmllist that returns something like this:

            <Oranges label="myoranges">
            <Orange id="1"/>
            <Orange id="2"/>
            <Strawberys lable= "Strawbery">
            <Strawberry id="1"/>

            then you could do something like this

            buttoOranges click=mydatagrid.dataprovider=myxmllist.@Oranges

            i haven't try it but i think it will work

            • 3. Re: Display a subset of data?
              ntsiii Level 3
              Yes, if your data is XML, use the e4x expression to populate the dataProvider.

              I would declare an instance variable:
              private var _xlData:XMLList;

              then in the button handler:
              _xlData = _xmlData.item.(category=="fruit");

              Bind the dataGrid to the variable:
              dataProvider="{xlData }"