Flex: Combobox creating dropdown with less values - apache-flex

I have an object that inherits from combobox. This is done so I can use a custom framework for creation and value setting and uses a 'id' / 'description' set for the dataprovider. When I set the value, i set the 'id' and the custom object looks through the dataprovider to find the matching id to find the index. When setting the value, I don't know the 'dscription', that is what the row source is for.
My problem is in that I need to display 'old' values when I first set the value through code, but I don't want to allow the user to see the 'old' value in the dropdown and allow them to select it.
Now, I've been trying to chase down the best way to do this. I'm assuming I need to either interrupt the creation of the dropdown dataprovider and populate it with a smaller list(using my own 'hideFromDropdown' property) or find out if there is a way to add a property to my dataprovider that causes the item to not be rendered by the dropdown. Perhaps eich 'item' in the dropdown has a visible property?
I was able to trace down to the combobox.getDropdown method, which creates a new dropdown from the dropdownfacrory. Unfortunatly, this is private so I can't override it to pass a partial rowsource. Now, all the dropdownfacory seems to do is return a basic list. Unfortunately I keep getting lost tracking down to find the place in the list or listbase objects where the individual item in the dataprovider gets rendered(or not). I believe I have traced to listContent:ListBaseContentHolder in ListBase which contains the data, but am constantly getting lost in the ambiguities.
I am using Flex SDK 3.6A in Adobe Flex Builder 3(built on the Eclipse engine)

You can use filterfunction on the dataProvider like arrayList/arraycollection. Checkout the example here
http://kirill-poletaev.blogspot.com/2011/07/arraycollection-in-flex-part-4.html

Related

How can You refresh a vaadin grid after data change

How can You refresh a grid, when some new row was added to its datasoruce container or one of its rows has been edited?
I have tried the hacks written about here (http://www.helpsforcoder.com/code/31861375-vaadin-refresh-grid-after-row-modification.html ) and here (deleted link to malicious advertisement) but with no positive result. I add / edit the row in a separate subwindow that 'pop-ups' over the view, where the grid, that should update its contents, is placed.
grid.getDataProvider().refreshAll();
Grid listens to changed property values. So if you are working on the property level of vaadin everything should be fine.
If you extract your bean out of the BeanItemContainer you directly manipulate the values of the bean. That way the property container can not recognize your manipluating action.
So you have to send your grid implementation a message, the properties have changed manually.
When your BeanItemContainer still has the hard reference to the changed object, grid.markAsDirty() should work.

Flex DataGrid prevent a filter from being applied automatically

To situate things I am working on a translation utility with a datagrid having 3 columns : translation code, reference text and target text.
The DataGrid's dataProvider property is bound to an ArrayCollection instance. The user can edit the grid and on a successful edit, the underlying collection is updated using the setItemAt() method. The collection also has a filter function to make it easier to find certain texts.
When the user clicks the 'apply filter' button the filter function is updated. This works well. The problem I have is that rows are hidden as soon as the underlying collection item change in a way that doesn't comply with the filter. The row is hidden immediately, which is not very user friendly. Rows should only hide (or be shown) when the 'apply filter' button is pressed.
I'm searching for a way to make this happen.
I assume you mean that the DataGrid's dataProvider is bound to an ArrayCollection instance?
Anyway, if you want to filter the DataGrid's dataProvider then that will remove rows from the DataGrid. You can remove the filter to add them back in. Something, conceptually like this:
collection.filterFunction = null;
collection.refresh();
If you are using the dataProvider as a source for multiple components, you can keep the filtering separate by using a different ListCollectionView for each one, but with the same source. Something like this:
component1.dataProvider = ListCollectionView(mySource);
component1.dataProvider = ListCollectionView(mySource);
Now applying a filter to one dataProvider will not affect the other.
If this doesn't help, you'll need to expand on the issue you're having and perhaps provide sample code.
After asking and looking around, I determine that there is no real way to do this. I did solve my problem however, by doing the filtering myself and only keeping a list of 'primary keys'. I then use that list to filter the collection.
The result is that rows can't suddenly disappear when records are changed, which is what I wanted.

how can we access a component within an itemRenderer from the main mxml?

I have an itemRenderer for a list where I'm just displaying items and their details respectively. I want to keep the details invisible and have a button,Show Details, in my main mxml file which when clicked would make the details visible.
So, my problem is in the clickHandler how can I access the details property within the itemRenderer from the main mxml?
Thanks in advance for your help
I would have a Boolean on the main which is what the itemRenderer keys off of. Accessing the itemRenderers of a list is not receommended because they are recycled, and operations cannot be guaranteed.
For an explanation see http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html
There are a few ways to approach this.
One is to use a global Singleton object that contains the "ShowDetails" value. Every itemRenderer can access that object and change it's settings. Cairngorm's ModelLocator is one example of a singleton that is commonly used in this way. I believe swiz has something similar. You could also roll your own if needed.
You could try to extend the List class The List keeps itemRenderers in an array, which I believe is protected. You'll have to extend the List, and make this protected array public. Then you'll be able to access the list of itemRenderers and modify properties on them directly.
However, I'm not sure I would recommend either approach. An itemRenderer really should choose what to display based on the data it is displaying; not some global variable. Can you change the objects in your dataProvider and have the itemRenderer update accordingly? It is a third option; although I'm not sure if it is any better, or worse, than the previous two approaches.
You could have a variable in the DataProvider array called 'show' thats set to false. In the itemrenderer bind the visible property of the details component to data.show.
When the show button is pressed, traverse the dataProvider array, and set the 'show' property to true. This will work
Bish

Flex ComboBox user choice reset

To be more descriptive here's a live example:
http://interklub.biz/CTPonLine.html
In last column there's a ComboBox with some values.
When user choose an option in ComboBox from first row and then scroll down the first choice disapears (comes back to default state).
There's something more strange, earlier I've tried to apply a one more ComboBox in additional column, with highly dynamic values (completly different for different rows), but with after same action (scroll down and then scroll down) values dataProviders from different ComboBox were switch.
It looks like you're not initializing your item renderer properly--when the renderer is reused, it's keeping its old value rather than updating from your data.
You should be able to resolve this by doing one of the following:
binding the item renderer's selectedValue to some property of its data element
overriding set data() to update the control for the current data
acting on the dataChange event and updating there
See Adobe's Working with Item Renderers for more.

Flex Combobox - Edit/Delete an option

I'm using a combo box control and the dataprovider is set as an XML.
After the dataprovider is set, I want to edit the text of the first option and also I need to insert an item in the second position.
How can I do this? Using an ItemRenderer?
Please give your suggestions.
You should edit the dataProvider itself. Make it an ArrayCollection (or something else that implements IList) and your combobox will automatically update as you make changes. Also make sure that the array collection is full of bindable objects.
Changing ArrayCollection is easy. You can just say dataProvider.getItemAt(0).labelProperty = "whatever" -- this assumes you have an object with a property of "labelProperty" and your combobox's labelField is set to it.
To add an item just use dataProvider.addItemAt(item, 1)

Resources