Single model - multiple filtered views - apache-flex

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.

Related

How to keep ranges on form datasource when manually add filters?

I have a strange problem on form: I added a range to filter records in datasource executeQuery() method, this works fine when opening form but if I set manually a filter in the grid header, the range set in ExecuteQuery() method are not applied. My ranges are definied as follow :
this.query.dataSourceNo(1).AddRange(fieldnum(MyTable,MyField)).Value('MyRangeValue');
I use a view as form DataSource, May be it's the problem.
Any ideas to always apply ranges and keep it even when manually add filters on grid?
Thanks for your help
You must apply the filter before the super() in executeQuery().
But I think your problem is you add the filter every time the executeQuery() is run, resulting in an OR in the SQL expression generated.
This is the way to do it:
QueryBuildRange qr = SysQuery::findOrCreateRange(this.query.dataSourceNo(1), fieldnum(MyTable,MyField));
qr.value(queryValue('MyRangeValue'));
qr.status(RangeStatus::Locked); // Or ::Hidden

data vs listData in Flex itemRenderer

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

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 ) );

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.

How to get data from dynmically created Treeview

I am using ComponentArt Third party controls for ASP.NET 2.0.
Here is the problem I am facing.
I created some ComponentArt.Web.UI.TreeView at runtime on Page_Load.
Now at click event of a button, I want to get values of the selected nodes in the treeview.
Can someone help?
Firstly I'm assuming you have MultipleSelectEnabled set to true to allow the selection of multiple nodes in the TreeView.
If you have that you can use the MultipleSelectedNodes property of the TreeView to get an array of TreeViewNodes.
From here you just need to iterate through the array and use the Value property of the nodes to get what you need.
So essentially something like this should work,
TreeViewNodes[] selectedNodes = treeViewID.MultipleSelectedNodes;
ArrayList values = new ArrayList(selectedNodes.Count);
foreach (TreeViewNode node in selectedNodes) {
values.Add(node.Value);
}
And now you have your selected node values in the ArrayList.

Resources