ItemRenderer Vs ItemEditor - apache-flex

What is the Difference between ItemRenderer and ItemEditor?
And When ItemRenderer is initializing and loading?
Regards,
Ravi

ItemRenderer is for configuring how something will look in a list control (i.e. a Picture + text might be a use case for an ItemRenderer). Thus "Render", how it will display (read-only).
ItemEditor is used when you want to override how the user might change the value in the list (assuming that you've set all the requisite editable properties on the controls in question to allow edits). A good example could be a date column. Perhaps you want a DataGrid to show a date as 12/28/2009 in the list, but when the user clicks on it, they get a DateChooser control to set a new date.

Related

Flex: Combobox creating dropdown with less values

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

How to disable automatic sorting in Editable Datagrid in Flex 4

I have an editable datagrid. If sorting is applied by clicking any header of datagrid, it works fine. But after that, if data values are changed in any row of datagrid, sorting is applied automatically. How to prevent from this behaviour? i.e. sorting should only be applied if user clicks on any header of datagrid and sorting should not be applied when user modifies data in grid.
You have to set sortableColumns to false and handle the headerRelease event, where you do the sorting manually on the data source.
<mx:DataGrid sortableColumns="false" headerRelease="onHeaderRelease(event)" ...
just call Object(owner).dataProvider.disableAutoUpdate() before committing the value in your item editor.
I know that you're asking this issue in Flex 4 but I hope the solution that I found in Flex 3 will help.
I also had the same exact problem but then I realized that something in the data must be triggering the sorting to happen.
And it turned out that I was setting the data to be [Bindable]. This made sense to see sorting happened automatically because the value change dispatch propertyChange event.
If you do need to make the data to be [Bindable], use custom binding:
http://livedocs.adobe.com/flex/3/html/help.html?content=ascomponents_4.html

Custom Combo box itemrenderer in Flex Datagrid

A combo box as an item renderer for a data cell in a Flex Datagrid has been demostrated at various blogs. What if that combo box has to have an external dataprovider that has to be set at the time of converting the renderer class to a ClassFactory.
Can this be done? Or is there a workaround?
Thanks in advance.
What if that combo box has to have an external dataprovider that has to be set at the time of converting the renderer class to a ClassFactory.
I don't think you meant to say what you said. But, at runtime, a renderer class is never converted into a ClassFactory. The renderer properties, such as itemRenderer or itemEditor are always factories. Now, the Flex compiler does some magic so that you specify the class name in MXML, it turns it into a ClassFactory. This happens at compile time.
I believe you mean that you want to set the dataProvider on the instance of the ComboBox as they are created by the ClassFactory. Is that correct? If so, you can extend the ClassFactory to do so.
You could also extend the ComboBox to be "dataProvider" aware. One approach is to build the remote service call to retrieve data directly into your extended ComboBox. Another might be to hard coded the dataProvider, Yet another might be to access some other application specific component for the data. One such example is using the Cairngorm ModelLocator.
Does that help?

how to loop over a datagrids rows in flex

I have a DataGrid which contains a DataGridColumn with a textinput and DataGridColumn with a Button.
The DataGrid is bound to some XML which displays values in the text box.
When the button for a row is clicked I need to get the value out of the text box and save it into the relevant XML node.
My solution was just to pass the id of the row to the button click event then loop over the rows until I find the id then just grab the text box value. Simple.
However the only advice I can find on looping over the rows is via the underlying dataProvider, which is nonsense as the two aren't the same thing.
Is this even possible? or is there a better way?
NOTE I would prefer not re-writing the markup, unless I have to.
Thanks
You are probably using an itemRenderer for your DataGridColumn to show the textBox (aka, TextInput component). I suggest that you dispatch a custom event out of the TextInput itemRenderer when you have a TextInput.dataChange event (or some other TextInput.Event that suits when you are ready to save the value).
http://livedocs.adobe.com/flex/3/langref/mx/controls/TextInput.html
Please remember that you need to bubble this event handling outside of the itemRenderer (e.g., the DataGrid) -- itemRenderers don't handle events well.
Also, one reason that a button to save your TextInput value is not a good idea, is because they are both itemRenderers, and it is hard to communicate between itemRenderers -- it is hard because Adobe deems it unclean code.
http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html
Also, this is another solution that changes the dataProvider for a ComboBox (in your case, it's a TextInput instead of ComboBox):
http://www.switchonthecode.com/tutorials/simple-datagrid-item-editor-in-flex
listData.rowIndex from the itemRenderer returns the current row index. You can read it from the click handler as:
private function clickHandler(event:MouseEvent):void
{
var listData:BaseListData = IDropInListItemRenderer(event.target).listData;
var clickedRowIndex:Number = listData.rowIndex;
}

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.

Resources