Binding e4x to dataProvider

18. March 2009 08:54

Let's say you have a set of redio buttons that act to filter your data collection.  It is possible to bind the dataProvider property of Flex Charts and AdvancedDataGrid controls to an e4x value.  There are still a couple little glitches working this way that I haven't quite figured out, but here is the basic idea.  The dataProvider property created as an e4x expression actually acts as the filter on the collection.  I have been trying to create a way to make the access of nested data easier for charts and grids.  Here is a quick example:

<?xml version="1.0"?>
<root>
   <person idPerson="1" name="Joe">
      <report idTime="1">
           <data id="11" value="red">
           <data id="21" value="blue">
      </colors>
   </person>
   <person idPerson="2" name="Sally">
      <report idTime="3">
           <data id="11" value="red">
           <data id="31" value="yellow">
      </colors>
   </person>
<root>



Here's what's going on.  In our data we have a person that has periodic reviews of their favorite colors.  The report node can have many individual entries (which we may not know at runtime).  In fact, we may not know the amount of data at all at runtime.  Since the amount of entries is completely dependent on the database, the only thing we can ensure is that the schema of the data will be returned according to how we have it set up.  So since we are working with nested data, we might have a need to show the user the favorite colors for each time interval.  To accomplish this we can use a repeater to create the radiobuttons and then assign the radiobuttons to a group.

<mx:XML id="coll" source="mydata.xml" format="e4x"/>
<mx:RadioButtonGroup id="grpPerson"/>
<mx:Repeater id="rptPerson" dataProvider="{coll..person}>
     <mx:RadioButton label="{rptPerson.currentItem.@name} value="{rptPerson.currentItem.@idPerson}"/>
</mx:Repeater>

This repeater will give us a way to see each person in the dataset and target that individual for use in our chart or grid.

<mx:AdvancedDataGrid id="grid" dataprovider="{coll.person.(@idPerson==grpPerson.selectedValue).report.data}">
      <mx:AdvancedDataGridColumn headerText="Color" dataField="@value"/>
</mx:AdvancedDataGrid> 



Presently, I'm trying to get the dataProvider to update on more than a single attribute value.  I almost had it last night but was unsuccessful.  In that scenario, I actually had two levels of filter radioButtons where the second was dependent on the first so that when the first radiobutton group changed, it would automatically update the second group.  I was able to get the radiobuttons to update properly, but for some reason, the dataProvider for the chart and the advanceddatagrid were unable to attain the value of the second group.selectedValue for comparison to the nodes in the XML.  Once I discover a solution, I will post it.

 

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments


Log in