How Can I Make a Flex 3 Datagrid Show only One Row of an ArrayCollection's Results?
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, the开发者_如何学JAVAn Jim's data shows up in the dataGrid.
Any suggestions or advice?
Thank you.
-Laxmidi
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>
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}"/>
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>
精彩评论