flex : add checkbox to datagrid control - apache-flex

i have a datagrid in my flex application, i am binding datagrid with arrayCollection,
now i want to add checkbox control to datagrid column and i dont want to bind chekcbox to arraycollection values.
i want something like this
without binding checkbox column field with arryayCollection.

Write an itemRenderer which is a checkBox, and handle change event. On change, set a property in the data to the selected boolean. Ex: data.rowIsSelected = checkBox.selected; The property does not need to already exist in the dataProvider.
Override set data property, and specify the check box's selected property to be the same as data.isRowSelected.
Later on, you can loop through the data set and get each item in the dataProvider's isRowSelected property to see if user had selected it or not.

Related

Can I populate datagrid using ArrayCollection.List or ArrayCollection.Source?

I have an ArrayCollection from a result handler in Flex that has FilterFunction, List, Source, Length.
How can I populate the datagrid using this data?
.....
Set the DataProvider value on the DataGrid to the ArrayCollection. It will use this to populate the display.
See the demo on the bottom of this page.

Flex:how to disable particular item in combobox?

I have ComboBox With ArrayCollection as DataProvider. Data will come from Databse as ArrayCollection. I'm Adding Item to ArrayCollection "-Select Item-" at 0th index and setting selected index=0 for combobox.
My question is How to disable that(-select Course-) item?
I recommend you to use prompt property of DropDownList or ComboBox for that and combine it with selectedIndex = -1 as initial value.
Worst case an item renderer to show things as disabled. Then simply ignore the click if it has the property disabled. (this implies your list is overloaded with a property like isDisabled.
Mylist.selctedItem.isDisabled

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

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.

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