0
votes

Is there a way to make a Flex 3 Datagrid show only the first node of an arrayCollection, instead of showing all of the arrayCollection's data?

    myDGArray = [
    {Name: "Judy", Talent: 'Pole-Dancing', Score: "40"},
    {Name: "Jane", Talent: 'Yodelling',    Score: "65"},
    {Name: "Jim",  Talent: 'Singing',      Score: "82"}
      ]

myAC:ArrayCollection = new ArrayCollection(myDGArray);

If I set the datagrid's dataProvider as myAC, then all of myAc's results will be listed in the dataGrid. How do I make it show only the first person's data, the not-so-hot Judy?

(The data in the myDGArray is actually from a database call. So, I'd like to return it all at once instead of making multiple server calls).

My goals is to have the datagrid load with the first person's data. And then have a comboBox control what data is shown in the dataGrid. So, if the user selects "Jim" in the comboBox, then Jim's data shows up in the dataGrid.

Any suggestions or advice?

Thank you.

-Laxmidi

3
I found a class that paginates an arrayCollection. boyzoid.com/blog/index.cfm/2008/2/25/… Thank you, Scott Stroz.Laxmidi

3 Answers

2
votes

Try this

<mx:DataGrid dataProvider="myAC">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="Name"/>
<mx:DataGridColumn headerText="Talent"/>
<mx:DataGridColumn headerText="Score"/>
</mx:columns>
</mx:DataGrid>
0
votes

If you always only want to show one record in your DataGrid, then you probably don't need to use the (rather heavy) DataGrid component. I would assign the data provider to the combo box and have something as simple as an HBox with Labels for the details. You can bind the label text to whatever detail of the selected combo box item:

<mx:Label text="{'Talent: " + myCombo.selectedItem.Talent}"/>
0
votes

Try this

<mx:DataGrid dataProvider="myAC">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="Name"/>
<mx:DataGridColumn headerText="Talent"/>
<mx:DataGridColumn headerText="Score"/>
</mx:columns>
</mx:DataGrid>