data vs listData in Flex itemRenderer - apache-flex

I was wondering what the difference between data and listData in itemRenderers in flex. I have worked with data in all of my itemRenderers.
Basically I want to know when to use which, where each gets set and if I can use them together?
Note that I am asking from a Flex3 point of view.

data is the data that the renderer should display. Use it to work with the original data currently assigned to the renderer.
listData is an additional object to provide you with information about the role of the renderer in the list (rowIndex, columnIndex, list component, uid, ...). Use it to perform some UI related operations such as formatting the first row differently or rows alternating depending on their vertical index, calling the list view component, etc.

Each item of your dataProvider collection is passed to data variable. You entirely define, what is passed to data by defining dataProvider content.
Information about the cell of datagrid/list (such as row/column index, label) is passed to listData (see BaseListData). To use this variable your itemrenderer should implement IDropInListItemRenderer interface.

See details about listData here. The main point is:
The list classes will pass more information to the renderer so that it
can determine which field to use at run-time.
So listData is for advanced usage for more complicated item renderers.

See this:
http://livedocs.adobe.com/flex/3/html/help.html?content=cellrenderer_4.html
And this:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/listClasses/IDropInListItemRenderer.html

Related

Programmatically adding a new row to a QAbstractListModel subclass

Within an already-instantiated QAbstractListModel subclass, how do I add a row with data in each column, and have the associated QListView display the new row?
It seems that the only way to do it is to reimplement insertRow and setData within my model, and then hack them together in some sort of sequence within another function to add a row. Must I do this? Surely Qt must make it easier to add a new row.
Thanks much!
--Dany.
Just change your model's data storage, in between beginInsertRows() and endInsertRows().
For instance, let's say you have a flat list model and your model stores the data internally in a QVector m_data. You want to prepend the list, i.e. insert a row at position 0:
beginInsertRows( QModelIndex(), 0, 0 ); //notify views and proxy models that a line will be inserted
m_data.prepend( somedata ); // do the modification to the model data
endInsertRows(); //finish insertion, notify views/models
I'm afraid you have to do it that way. From the docs:
Models that provide interfaces to resizable list-like data structures can provide implementations of insertRows() and removeRows().

flex Dictionary dataProvider?

I have a Dictionary that I'd like to bind as the dataProvider for an mx:ComboBox. e.g., when I do this:
mydict[somenewkey]= somenewval;
I'd like the combobox to update its contents.
The problem is that Dictionary doesn't seem to be Bindable. If I were using an Array, I'd use ArrayCollection. But there doesn't seem to be a corresponding DictionaryCollection or HashCollection. What to do?
A Dictionary is not the appropriate object for a dataProvider of a list based class.
I suspect your display problems have nothing to do with data binding, but rather other issues, such as a dictionary does not have a length property.
I suspect the ComboBox will treat your dictionary as a single object, not as a collection of multiple objects.
Try using an ObjectProxy:
http://www.adobe.com/livedocs/flex/3/langref/mx/utils/ObjectProxy.html
Isn't what you're looking for just a combination of the setItemAt and getItemIndex methods of the ArrayCollection?
_myAC.setItemAt( somenewval, _myAC.getItemIndex( somenewkey ) );

Single model - multiple filtered views

I have data model (dataProvider as ArrayCollection) i want to display in few views , each view should show filtered data.
As you probably know, filterFunction is property of ArrayCollection,so I can't use this solution (unless creating new instance of ArrayCollection for each view on top original and impementing filterFunction).
Are there better approaches ?
Thanks
you can use ListCollectionView for each view that use your array, and every time you can pass to it the same array but filtered differently as source...
You're using the same ArrayCollection as dataProvider across multiple views, and setting the filterFunction in view1 persists into view2?
You could probably put code to change the filterFunction for each view in that view's "show" event. If you wanted to default each view to be unfiltered, pass in a function that just returns true.

Flex AdvancedDataGrid AdvancedDataGridRendererProvider childrenField ArrayCollection - Question about behaviour

I have a main class ClassA that has a bunch of "normal" properties that are simple datatype like ints, strings, etc. It also has one property ("childItems") that is an ArrayCollection of ClassB.
I am using an ArrayCollection of ClassA as the source for an hierarchical data provider for an AdvancedDataGrid. I set the childrenField to "childItems".
I want to display some information about the list of ClassB objects in a nested table and pie chart, so I configure an AdvancedDataGridItemRendererProvider (columnIndex = 0, columnSpan = 0, depth = 2) and point it to my custom renderer which is an HBox with the table and the pie chart in it.
In order to see what is being set, I override the "set data" function in my custom renderer and what I see is that each instance of ClassB in the ArrayCollection is passed to the renderer separately.
Here is my question: I expected the whole ArrayCollection of ClassB instances to be passed to the custom renderprovider once and not each item in the child list individually. How do I make the ADG understand that the whole property is supposed to be passed as the data to the renderer and not each entry separately?
Btw, when I change the data type of "childItems" from ArrayCollection to ArrayList, the whole list gets passed and I can easily do what I want to do. But based on my understanding, ArrayList is not really supposed to be used and ArrayCollection is better or at least more common.
Any insights on that would be appreciated.
Thanks!
I pretty much stuck with the ArrayList instead of ArrayCollection as property data type. Then the whole ArrayList gets passed one time to one renderer instead of one renderer per item in the ArrayCollection.
That is not particularly nice, since the source data structure is an ArrayCollection and all my other lists are ArrayCollections, but that worked for me and I never bothered trying to find a different solution for that.

flex datagrid - item renderers and skipping rows

HI,
I have a datagrid with 6 columns, each with its own item renderer. In the first column i want to be able do a check and see if the column contains some valid data, if not then i want to skip this row and go to the next. In other words i want a way to tell my datagrid to stop processing the rest of the item renderers for the current data object and skip to the next. Any ideas?
I'd say your best bet is to use the filterFunction property on ListCollectionView objects (such as ArrayCollection). This allows you to filter out the objects you don't want to show in your DataGrid before they're displayed in the grid, and should avoid any itemRenderers being processed altogether.
If you still want the "skipped" object to display in the data grid and just change how the item renderers respond to it, then you'll need to write code for that in the renderers.
Inside of the item renderer, you can access the data values of the previous columns. You should examine the listData property available in the item renderer and use your findings to configure how the item renderer should display.
You can find information about the listData here: http://livedocs.adobe.com/flex/3/langref/mx/controls/dataGridClasses/DataGridListData.html
To examine previous values, you might code something like this:
var dgListData:DataGridListData = DataGridListData( listData );
// Process all columns before the current one.
for ( var i:int = 0; i < dgListData.columnIndex; i++)
{
// Do something here to examine previous data
// If we should stop processing based on previous values
// then hide everything inside of this renderer (perhaps
// move to a state name 'empty' that has no children), else
// move to the state that renders something.
currentState = shouldSkipObject ? 'empty' : 'normal';
}
If you want more specific help writing the code inside of the item renderer, please include a sample of what the data looks like inside of the data grid as well as a description of what the item renderer should actually do.

Resources