开发者

Flex DataGrid: Get Data Object from row index & vice versa?

Using a standard Flex DataGrid, is there an easy way to determine the grid row index given the data object or index of the data object in the data provider? On the flip side, is there a w开发者_StackOverfloway to get the index of an object in the data provider based on the DataGrid row index? Thanks in advance!


Assuming I understand what you're asking for correctly and assuming your dataProvider is an ArrayCollection:

To get the selected row's index in your dataProvider:

var rowIndex:int = myArrayCollection.getItemIndex(myDataGrid.selectedItem);

To get the object in your dataProvider from the DataGrid:

var obj:Object = myDataGrid.selectedItem;

Since DataGrid's recycle their itemRenderers to improve memory performance, there's no specific row index for a given object in your dataProvider. As you scroll and records are no longer visible, those records itemRenderers are reused for new records that scroll into view. You can read up more on itemRenderers and recycling here.

EDIT: Here's a link to an example on how to filter your data in a dataGrid:

http://www.flex-blog.com/arraycollection-filter-example/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜