How to change datagrid cell's itemRenderer dynamically - apache-flex

i have a simple datagrid having 2 columns named as image and place. where image column has mx.controls.Image itemRenderer and place is simple. my requirement is to change itemRenderer of image cell when it will be clicked. i means to say when user click on any image from image column than i want to show that image path in editable mode and when user edit that path then the selected cell will start displayed the updated image.
i dont know how to do this and getting depressed . please anyone help me ! :(

You don't need to change itemRenderer for that - just implement that code in your single item renderer. You can add listeners inside it and change the contents of the current cell.

I suggest when going into editable mode for your DataGrid: Also create an itemEditor for your Image column, make it an extended TextInput class. This extended TextInput class will change the data object's imageAddress/url when you are done editing ("itemEditEnd" event).
Let me know if this helps, thanks!

Related

Binding column text property to another property with refresh (JavaFX)

Could somebody tell me how shold I approach binding the text property of a column header in a TableView to another property, that can be changed with a combobox selection?
I tried column.textProperty().bind(myProperty) , but the column header doesn't refresh the text when myProperty changes. It only happens after I click on the column header as if I wanted to sort the column. Is there any way to make it refresh automatically when changed ? Or does anybody have other suggestions how to approach this ?
Found out it was because I've accidentally put the method that changes the property into a block that runs in a separate thread.

Flex 4.6 Mobile - how to know which itemrenderer is visible

I have a sparks List with the following attributes:
verticalScrollPolicy="off"
horizontalScrollPolicy="on"
pageScrollingEnabled="true"
scrollSnappingMode="leadingEdge"
and inside is an ItemRenderer that takes up a full screen for each item. So basically it is a horizontal list that lets you swipe left and right one page at a time. Note the scrollSnappingMode is on, so the pages always snap perfectly on the page.
Also, I am setting "useVirtualLayout=true" on the Layout, so I have virtual ItemRenderers that are getting recycled.
My question is this: how do I know which ItemRenderer is currently on the screen? Is there an event or property to watch that lets me know when this page has snapped into view and is the currently visible page?
how do I know which ItemRenderer is currently on the screen?
In the situation you describe, which uses Virtual Layouts and only one element displayed on screen at a time; there will only be a single itemRenderer.
You can access the dataProvider element of the itemRenderer using the data property on your itemRenderer.
You can find the index of your data in the dataProvider using the itemIndex property on the itemRenderer.
If you want to know when the list changes from the component that contains the list; you may try listening to the change event; but I'm not sure if that will give you want you need; as it is possible to scroll without selecting a new item.

Flex TileList itemrenderer + scroll = HELL

I'm going insane over this issue. Basically, I have a TileList with a custom item renderer that has a TextInput in it. Let's say that the list can show 4 items at once, if there are 5 items and I edit the text on the first one, the fifth will be edited also. In general if an item is out of view, it will be change when I edit one that is showing.
Also, I had overriden the TileList class to expose the rendererArray property (so that I could access the texts on each renderer) but it will only return the renderers which are displayed.
Any help is appreciated. I need to know how to override this weird behaviour with itemrenderers that aren't currently displayed. Thanks.
Ok, if anyone runs into a similar issue, here is what you need to do:
First of all, avoid trying to iterate through the itemrenderers like I did. If you need a TextInput or another control on your TileList, make sure that these controls are bound to a property on your data object, otherwise off-screen items will have incorrect values since their itemrenderers will be recycled from the items that left the screen when you scrolled.
If you think it through, any requirement can be solved by iterating through the dataprovider instead of the itemrenderers.
Also, if you try to expose the rendererArray property like I did, notice that you will only be able to iterate through the itemrenderers that are currently displayed, since those that would belong to the items that are off-screen will not be created yet.
I hope this wasn't too confusing..

How can I add rows of data with dynamic images in Flex?

I want to add specific images to a datagrid row, depending on the data displayed on that row. These images need to be functional buttons with click handlers and everything.
For example, if a row displays status of a certain element, like "Editable" then the image displayed in the cell next to it needs to be a green flag, if it isn't Editable then I red flag should appear.
If you just need images and click handlers, there is an option to embed icons inside a datagrid.
Also, for a datagrid ,clicking on any row triggers the click event,the handler to which will give you datagrid.selectedIndex as the index of the row you clicked, which you can then use to get the data in that specific row and according to the data do a specific action you need.
To render icons in datagrid, you might want to check for labelFunction attribute, which allows you to specify a function , each time data in a datagrid row is filled, which yuo can use to determine the icon you would need the datagrid to render and show to the user.

ItemRenderer Vs ItemEditor

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.

Resources