Monday, October 8, 2007

DataSets In Flex: Basic

There are two approaches to dealing with data sets:
1.Using a Repeater in MXML
2.Use data set as a dataProvider

List based controls enable user to scroll through a list of items and select one or more items from the list. All Flex-based list components inherit from ListBase class. They include:
DataGrid, HorizontalList, List, ComboBox, TileList, Tree
They all have the dataProvider property

The property displayed by the list can be specified in labelField property. This is ok if we wish to use one property as label. If we wish to combine various properties, we have to write a function and assign it to labelFunction property. eg:
this function
private function multiPropComboLabelFunc(item:Object):String{
return "label for"+item.name+","+item.id;
}
may be given as
<mx:HorizontalList dataProvider="{myCol}" labelFunction="multiPropComboLabelFunc"/>

Notice that even when there is a parameter to the function in script, the same need not be given in the tag. Flex automatically passes the correct object.

By default HorizontalList and TileList permit only text to be displayed. This can be overridden using the itemRenderer property. itemRenderer can be an mxml component made to customize the display as desired. When you specify the file to be used as itemRenderer, you do not specify the extension (which can be .mxml or .as). The data passed to the renderer will be in an object called "data".

Questions:
  1. How will you determine what is displayed by a list control?
  2. If you want to display more that text in a list based control, how can you do it?

No comments: