how to assign dataProvider to DataGrid Dyanmically in flex? - apache-flex

i done as follows
i have a method with brings data of particular table, as given my parameter to that method,
now i want to fetch data from corresponding table and it too list, and send back flex and form dynamically Grid & add dataprovider dynamically as for its corresponded table colomns in flex side ?
Remote objec(java class)
public List<List<String>> getMasterTableData(String name)
{
String designMaster = "tbl_design_master"+name;
String masterTableName = "tbl_master"+name;
String[][] res ;
List<List<String>> list = new ArrayList<List<String>>();
try
{
st = connection.createStatement();
ResultSet rs1 = st.executeQuery("select * from "+designMaster);
int len = 0;
while(rs1.next())
{ len++; }
ResultSet rs2 = st.executeQuery("select * from "+masterTableName);
while(rs2.next())
{
List<String> ll = new ArrayList<String>();
for(int i=1;i<=len; i++)
{
ll.add(rs2.getString(i));
}
list.add(ll);
}
}
catch (SQLException e) {
e.printStackTrace();
}
return list;
}
flex code :
<mx:RemoteObject id="RO" destination="adminServiceImpl">
<mx:method name="getMasterDesign" result="getMasterDesignRH(event)" fault="FH(event)" />
<mx:method name="getMasterTableData" result="getMasterTableDataRH(event)" fault="FH(event)"/>
</mx:RemoteObject>
<mx:Script>
<![CDATA[
[Bindable] private var ac:ArrayCollection = new ArrayCollection();
public function init(Str:String):void
{
RO.getMasterDesign(Str);
Application.application.selectedgridItem = Str;
RO.getMasterTableData(Str);
}
private function getMasterDesignRH(event:ResultEvent):void
{
Application.application.designList = event .result as ArrayCollection;
var aColumns:Array = new Array();
for(var i:int=0; i< Application.application.designList.length; i++)
{
var dgc:DataGridColumn = new DataGridColumn();
dgc.headerText = Application.application.designList.getItemAt(i).colName;
//dgc.dataField = Application.application.designList.getItemAt(i).colName;
aColumns.push(dgc);
}
mainGrid.columns = aColumns;
}
private function getMasterTableDataRH(event:ResultEvent):void
{
ac = event.result as ArrayCollection;
mainGrid.dataProvider = ac;
}
private function FH(event:FaultEvent):void{
Alert.show(event.fault.faultString);
}
]]>
</mx:Script>
<mx:HBox width="100%" height="80%">
<mx:DataGrid id="mainGrid" width="100%" height="100%" />
</mx:HBox>
getMasterDesign is an ArrayCollection, which is filled with the column names and components to be displayed
Ex : getMasterDesign(emp)
empMasterDesign table looks like as follows
colName component
--------------------
EmpName textBox
empSal textBox
empDesi ComboBox
empMasterData:
empName | EmpSal | EmpDesi
abc 1000 Cler## Heading ##ck
xyz 2000 Manager
Now i want this create a Datagrid in flex dynamically by using its design & master data table in action script i done everyting , my dataGrid had formed as for his master design,but data is not showing ?

You must set the dataField to the appropriate value. From the given data, it looks like colName field in the metadata and its corresponding name in the table are not the same. For example it is EmpName in the design and empName in the original table; none of the fields match - empSal vs EmpSal, empDesi vs EmpDesi. Fix that, assign colName to the dataField, and you should be good to go.

Related

UWP: How to map arbitrary data to Telerik RadDataGrid

So I have a situation in which I am receiving a collection of Dictionary(string, string) entries where the key of each entry is the column name & value the, well, value. I want to push these to a RadDataGrid so that each dictionary maps to a row. If I knew what/how many columns I'd be getting in advance, I'd just map them to an object and have done with it. Unfortunately, it could be different every time, so that won't work.
So far I'm having no luck. I've tried mapping it*(the collection) directly, converting it to dynamic objects & XMLDocument, none of which worked. Also just got the Fall Creators Update & tried mapping it to a DataTable, no luck there either.
I've been experimenting with mapping the DataTable's DefaultView to the grid's ItemsSource after manually adding columns, but while I get the right # of columns and headers, I still don't get the field values. Not sure where to go next.
Mind you, I'm not married to Telerik. If someone else knows a suitably usable UWP data grid solution that will let me map arbitrary data like this, I'd love to hear about it.
Example using a standard UWP app:
MainPage.xaml:
<Page xmlns:my="using:Telerik.UI.Xaml.Controls.Grid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestTelerikDataGrid"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ComponentModel="using:System.ComponentModel"
x:Class="TestTelerikDataGrid.MainPage"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="0,0,0,125">
<my:RadDataGrid Margin="0,0,0,-125" x:Name="dataGrid" AutoGenerateColumns="False" >
</my:RadDataGrid>
</Grid>
</Page>
And the back-end:
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using Windows.UI.Xaml.Controls;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace TestTelerikDataGrid {
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page {
private ObservableCollection<Dictionary<string, string>> items = new ObservableCollection<Dictionary<string, string>>();
public ObservableCollection<Dictionary<string, string>> ItemDictionary {
get {
return items;
}
set {
items = value;
}
}
public DataTable Items { get; set; }
public MainPage() {
this.InitializeComponent();
CreateItems(); // creates sample data structurally identical to what we'll get in the actual app (i.e., obsv. collection of dictionaries)
CreateTable(); // attempt to take the collection created above and map it to the RadDataGrid
}
private void CreateItems() {
for (int i = 0; i < 5; i++) {
Dictionary<string, string> row = new Dictionary<string, string>();
row["A"] = "A" + i.ToString();
row["B"] = "B" + i.ToString();
row["C"] = "C" + i.ToString();
ItemDictionary.Add(row);
}
}
private void CreateTable() {
Items = new DataTable();
if (ItemDictionary.Count == 0) return;
foreach (KeyValuePair<string, string> entry in ItemDictionary[0]) {
DataColumn column = new DataColumn(entry.Key);
Items.Columns.Add(column);
Telerik.UI.Xaml.Controls.Grid.DataGridTextColumn dgc = new Telerik.UI.Xaml.Controls.Grid.DataGridTextColumn();
dgc.Name = entry.Key;
dgc.Header = entry.Key;
dgc.PropertyName = entry.Key;
dataGrid.Columns.Add(dgc);
}
foreach (Dictionary<string, string> rowEntry in ItemDictionary) {
DataRow row = Items.NewRow();
int col = 0;
foreach (KeyValuePair<string, string> entry in rowEntry) {
row[entry.Key] = entry.Value;
}
Items.Rows.Add(row);
}
DataView dv = Items.DefaultView;
dataGrid.ItemsSource = dv;
}
}
}
Ideally, this will result in a table with 5 rows, 3 columns (A, B, C) and the fields showing the correct value (e.g., first row reading A0, B0, C0).
I've been experimenting with mapping the DataTable's DefaultView to the grid's ItemsSource after manually adding columns, but while I get the right # of columns and headers, I still don't get the field values. Not sure where to go next.
Those are all part of UWP 2.0 that came with the Fall Creators Update. I believe it's build 16299 or something like that. Sorry, should have mentioned that's the build I'm using.
The RaDataGrid doesn't support setting DataTable or DataView as ItemsSource directly. You need to cast to an IEnumerble collection instead of DataView.
Please see this thread on Telerik forum for more details: binding-dictionary-to-raddatagrid
In the end, I wound up creating a generic "GridRow" class with properties "Item00"..."Item99" and just mapped the data to that instead. It's a pill but it works. Just putting this here for the next person.
public class GridRow {
public Int32 Index { get; set; }
public string Item00 { get; set; }
public string Item01 { get; set; }
public string Item02 { get; set; }
...etc
}
public ObservableCollection<GridRow> GridData { get; set; }
And here's how you populate that:
GridData = new ObservableCollection<GridRow>();
foreach (Dictionary<string, string> record in ViewModel.ItemsSource) {
GridRow gridRow = new GridRow();
gridRow.Index = rowIndex;
colIndex = 0;
foreach (DataGridHeader header in ViewModel.Headers) {
gridRow.GetType().GetProperty(string.Format("Item{0:D2}", colIndex)).SetValue(gridRow, record[header.Name]);
colIndex += 1;
}
GridData.Add(gridRow);
rowIndex += 1;
}
You get the idea.

Add "New item Label" to Spark ComboBox

I have a Custom Spark ComboBox which contains a list of items. I want to Add a new Item to the ComboBox stating the text "Add new Item", which on selecting popup a window to do some operations.
I have achieved this by creating a new object of the same type of the entities in the data provider, with the LabelField of the new object having the text "Add new Item". I have override the set dataProvider method and in the custom combobox.
But this adds the values to the Actual List which is binded to the DataProvider. The list is used in the business logics. So i do not want this to happen. I have lot of Entity Classes. i could not change all the objects.
All i want is to achieve the same functionality in my custom component without changing the other code. I have also tried to create a new instance of dataProvier but i noticed that the binding of the List and dataprovider is lost when i created a new instance.
Kindly help.!!
Edited:
ExtendedComboBox.as
package components
{
import flash.utils.getDefinitionByName;
import mx.collections.ArrayCollection;
import mx.collections.IList;
import spark.components.ComboBox;
import spark.events.DropDownEvent;
public class ExtendedComboBox extends ComboBox
{
private var _addItem:Boolean = false;
private var _addItemLabel:String = "Create New Item" ;
private var _dropDownClass:String = null ;
private var originalDP:IList ;
private var dpEdited:Boolean = false;
public function ExtendedComboBox()
{
super();
this.addItem = true;
this.addEventListener(DropDownEvent.CLOSE, dropDownCloseEventListner );
this.addEventListener(DropDownEvent.OPEN, openDropDownEvent );
}
public function get dropDownClass():String
{
return _dropDownClass;
}
public function set dropDownClass(value:String):void
{
_dropDownClass = value;
}
public function get addItemLabel():String
{
return _addItemLabel;
}
public function set addItemLabel(value:String):void
{
_addItemLabel = value;
}
public function get addItem():Boolean
{
return _addItem;
}
public function set addItem(value:Boolean):void
{
_addItem = value;
}
private function dropDownCloseEventListner(event:DropDownEvent):void{
}
protected function openDropDownEvent(event:DropDownEvent):void{
if(addItem)
{
// if(value) value = new ArrayCollection();
var value:IList ;
if(originalDP == null) value = new ArrayCollection ;
else value = new ArrayCollection( originalDP.toArray() ) ;
var tempObj:Object;
var createItemPresent:Boolean =false ;
if(dropDownClass != null)
{
var TempClass = flash.utils.getDefinitionByName(dropDownClass) as Class;
tempObj = new TempClass();
if(value.length >0)
{
// trace(value.getChildAt(0)[this.labelField]) ;
if(value.getItemAt(0)[this.labelField] == addItemLabel)
createItemPresent = true ;
}
if(!createItemPresent)
{
tempObj[this.labelField] = addItemLabel ;
var sort = (value as ArrayCollection).sort ;
value.addItemAt(tempObj, 0);
(value as ArrayCollection).sort = sort ;
dpEdited = true;
}
}
}
super.dataProvider = value;
}
override public function set dataProvider(value:IList):void{
if(!dpEdited)
{
originalDP = value;
dpEdited = true;
}
/*if(addItem)
{
// if(value) value = new ArrayCollection();
var tempObj:Object;
var createItemPresent:Boolean =false ;
if(dropDownClass != null)
{
var TempClass = flash.utils.getDefinitionByName(dropDownClass) as Class;
tempObj = new TempClass();
if(value.length >0)
{
if(value.getItemIndex(0)[this.labelField] == addItemLabel)
createItemPresent = true ;
}
if(!createItemPresent)
{
tempObj[this.labelField] = addItemLabel ;
var sort = (value as ArrayCollection).sort ;
value.addItemAt(tempObj, 0);
(value as ArrayCollection).sort = sort ;
}
}
}*/
super.dataProvider = value;
}
}
}
MyEntityObj.as
package entity
{
public class MyEntityObj
{
private var _name:String ;
private var _age:int ;
private var _company:String;
public function MyEntityObj()
{
}
public function get company():String
{
return _company;
}
public function set company(value:String):void
{
_company = value;
}
public function get age():int
{
return _age;
}
public function set age(value:int):void
{
_age = value;
}
public function get name():String
{
return _name;
}
public function set name(value:String):void
{
_name = value;
}
}
}
And Implementation Sample - ComboImpl.mxml
<?xml version="1.0" encoding="utf-8"?>
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
import mx.events.FlexEvent;
[Bindable]
private var samplDP:ArrayCollection;
protected function application1_initializeHandler(event:FlexEvent):void
{
samplDP = new ArrayCollection ;
samplDP.addEventListener(CollectionEvent.COLLECTION_CHANGE, changeHandlerFunc );
var sampVO:MyEntityObj;
for(var i:int = 0; i<5;i++)
{
sampVO = new MyEntityObj;
sampVO.name = "Name " + i;
sampVO.age = i;
sampVO.company = "Company " + i;
samplDP.addItem(sampVO);
}
}
protected function changeHandlerFunc(event:CollectionEvent):void{
var nameList:String = "" ;
for each(var myObj:* in samplDP)
{
nameList += myObj.name + ", " ;
}
changeHandler.text = nameList ;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:VGroup>
<s:Label id="changeHandler" />
<components:ExtendedComboBox dataProvider="{samplDP}" labelField="name" addItem="true" dropDownClass="entity.MyEntityObj" addItemLabel="Create Sample" />
</s:VGroup>
As commented in the set DataProvider Overridden method and the in the DropDownClose events addition of the new item directly affects the original List. i do not want this to happen.
Note that its just a sample implementation. The component creation in my project actually happens in the action script class dynamically.
Kindly help.!!
It sounds to me like:
You're going to have to extend the ComboBox (If you drill down into how it's implemented, possibly the DataGroup) to include your extra "Add New Item" item w/o it being in the dataProvider.
I expect this to be very difficult, but have not reviewed the code for this purpose.

How to read the Dynamic form Child data in Flex?

i created a form dynamically by adding each component in action script,
now i want to get back the text/data entered in to that each component dynamically?
private function loadAllComponents():void
{
var formItemArray:Array = new Array();
for(var i:int=0; i< Application.application.designList.length; i++)//which had the colonName, colComponet to be dispalyed,
{
var fm:FormItem = new FormItem();
fm.label = Application.application.designList.getItemAt(i).colName;
var comp:String = Application.application.designList.getItemAt(i).component;
switch(comp)
{
case "TextBox":
var ti:TextInput = new TextInput();
ti.id = Application.application.designList.getItemAt(i).component;
fm.addChild(ti);
break;
case "TextArea":
var ta:TextArea = new TextArea();
ta.id = Application.application.designList.getItemAt(i).colName;
fm.addChild(ta);
break;
case "ComboBox":
var mycb:myComboBox = new myComboBox();
mycb.getAllMasterCBData(Application.application.selectedgridItem, Application.application.designList.getItemAt(i).colName);
fm.addChild(mycb);
break;
case "DateField":
var df:DateField = new DateField();
df.id = Application.application.designList.getItemAt(i).component;
fm.addChild(df);
break;
}
myform.addChild(fm);
}
}
private function saveToDb():void // Here i wan to read all the formdata
{
var formItems:Array = myform.getChildren();
for each (var item:UIComponent in formItems)
{
if (item is TextInput)
{
var text:String = Object(item).text;
Alert.show("came here");
}
else if (item is DateField)
{
var date:Date = DateField(item).selectedDate;
}
}
}
]]>
</mx:Script>
<mx:Form id="myform" cornerRadius="5" borderColor="#B7BABC" borderStyle="solid" width="100%" height="100%" />
<mx:HBox width="100%" height="100%" >
<mx:Spacer width="120"/>
<mx:Button label=" Save " id="saveBtn" click="saveToDb()" />
</mx:HBox>
You're creating the input components in ActionScript, but based on this code you are not creating them dynamically; you're just hard coding them. With your given sample, you'll know the components you are creating at compile time.
You'll need to store a reference to the form items you create; make them public variables instead of 'var' local variables. Kind of like this:
protected var ti:TextInput ;
protected var ta:TextArea ;
protected var df:DateField;
Then in your creation method, do something like this:
ti = new TextInput();
ti.id = Application.application.designList.getItemAt(i).component;
fm.addChild(ti);
ta = new TextArea();
ta.id = Application.application.designList.getItemAt(i).colName;
fm.addChild(ta);
df = new DateField();
df.id = Application.application.designList.getItemAt(i).component;
fm.addChild(df);
myform.addChild(fm);
Then when you need to access them, just do something like this:
private function getMyformData()
{
ti.text;
ta.text;
}
If you're generating the form components at run time based on data, then store then form elements in an array of some sort.
You could also work something out by looping over all children of your container, although that wouldn't be my first approach.
Since poster posted more complete code; here are some additions. I added the protected array of all form items and in each 'switch' block; the new input element is pushed onto the array.
<mx:Script>
protected var itemsArray : Array = new Array();
private function loadAllComponents():void
{
var formItemArray:Array = new Array();
for(var i:int=0; i< Application.application.designList.length; i++)//which had the colonName, colComponet to be dispalyed,
{
var fm:FormItem = new FormItem();
fm.label = Application.application.designList.getItemAt(i).colName;
var comp:String = Application.application.designList.getItemAt(i).component;
switch(comp)
{
case "TextBox":
var ti:TextInput = new TextInput();
ti.id = Application.application.designList.getItemAt(i).component;
fm.addChild(ti);
itemsArray.push(ti)
break;
case "TextArea":
var ta:TextArea = new TextArea();
ta.id = Application.application.designList.getItemAt(i).colName;
fm.addChild(ta);
itemsArray.push(ta)
break;
case "ComboBox":
var mycb:myComboBox = new myComboBox();
mycb.getAllMasterCBData(Application.application.selectedgridItem, Application.application.designList.getItemAt(i).colName);
fm.addChild(mycb);
itemsArray.push(mycb)
break;
case "DateField":
var df:DateField = new DateField();
df.id = Application.application.designList.getItemAt(i).component;
fm.addChild(df);
itemsArray.push(df)
break;
}
myform.addChild(fm);
}
}
The sateToDb method will change to be something like this:
private function saveToDb():void // Here i wan to read all the formdata
{
var formItems:Array = myform.getChildren();
for each (var item:UIComponent in itemsArray )
{
if (item is TextInput)
{
var text:String = Object(item).text;
Alert.show("came here");
}
else if (item is DateField)
{
var date:Date = DateField(item).selectedDate;
}
}
}
]]>
</mx:Script>
Edited Response:
OK, I think I see the issue.
You're adding your data controls to FormItems and adding those to the Form. But then you're iterating over the Form's children and as if they were the data controls and not FormItems.
Without commenting on the rest of the code, have a look at what this updated function is doing to retrieve the data controls:
private function saveToDb():void
{
var formItems:Array = myform.getChildren();
for each (var item:FormItem in formItems)
{
var itemChildren:Array = item.getChildren();
for each (var control:UIComponent in itemChildren)
{
if (control is TextInput)
{
var text:String = Object(item).text;
Alert.show("TextInput");
}
else if (control is DateField)
{
var date:Date = DateField(item).selectedDate;
Alert.show("Date");
}
}
}
You can delete the formItemArray variable too, it's not needed since we're getting the list of children from the Form and FormItems.
Original response:
If you keep a reference to each of the dynamic form items in an Array you can iterate over each of them in your getMyFormData() function.
e.g.
protected var formItems:Array = new Array();
// Other class stuff here...
var ti:TextInput = new TextInput();
ti.id = Application.application.designList.getItemAt(i).component;
formItems.push(ti); // Add item to array.
fm.addChild(ti);
var ta:TextArea = new TextArea();
ta.id = Application.application.designList.getItemAt(i).colName;
formItems.push(ta); // Add item to array.
fm.addChild(ta);
var df:DateField = new DateField();
df.id = Application.application.designList.getItemAt(i).component;
formItems.push(df); // Add item to array.
fm.addChild(df);
myform.addChild(fm);
<mx:button click="getMyformData()"/>
private function getMyformData()
{
//How to get the myform Data dynamically here after validations... ? &
for each (var item:UIComponent in formItems)
{
if (item is TextInput || item is TextArea)
{
// Cast to Object to access the 'text' property without the compiler complaining.
var text:String = Object(item).text;
// Do something with the text...
}
else if (item is DateField)
{
var date:Date = DateField(item).selectedDate;
// Do something with the date...
}
// Insert additional type checks as needed.
}
}
You'll have to work out what to do with the data on your own though :)
If you are using a separate list make sure you clear out the formItems array when you're done with it so you don't have references to the items keeping them in memory unnecessarily.
Instead of keeping a separate array of form items you could also iterate over the children in the fm container. You might have to make some assumptions about the children you'd be accessing but it looks like you have control over all of the children being added so that's no problem.
I hope that helps...
:)

Disabling radiobuttongroup

Since Repeater component won't generate radiobuttongroup in mxml, and since I can't do the same through ActionScript because radiobuttongroup doesn't have an id property when I try to create it that way, is there a way to disable radiobuttons at all? As far as I can see, the only thing I can set and access is groupName property of radiobuttons.
For Repeater component I tried using xml directly
<mx:XML id="xquiz" source="quiz.xml" />
with this code:
<mx:Repeater dataProvider="{xquiz.question}" id="rep">
<mx:Label text="{rep.currentItem.content}" />
<mx:Repeater dataProvider="{rep.currentItem.answer}" id="rep2">
<mx:RadioButton label="{rep2.currentItem}" groupName="{'rbg'+rep.currentIndex}" click="checkAnswers(event)" value="{rep2.currentItem.#correct}" />
</mx:Repeater>
</mx:Repeater>
and cannot use repeater to generate radiobuttongroup since it's not a visible component.
I also tried ActionScript approach but with HTTPService mxml component to fetch xml file.
<mx:HTTPService id="srv" url="quiz.xml" resultFormat="e4x" result="handleResult(event);" fault="handleFault(event);"/>
and here's actionscript snippet:
private var xQuizData:XML
private function handleResult(event:ResultEvent):void {
xQuizData = event.result as XML;
initApp();
}
private function initApp():void {
var cnt:Number = 0;
for each (var question:XML in xQuizData.*) {
var lbl:Label = new Label();
lbl.text = question.content;
panel.addChild(lbl);
lbl.visible = true;
var cnt2:Number = 0;
for each (var answer:XML in question.answer) {
var rb:RadioButton = new RadioButton();
rb.id=String(cnt);
rb.label=answer;
rb.groupName="rbg"+String(cnt);
if (answer.hasOwnProperty("correct")) {
rb.value=true;
}
panel.addChild(rb);
rb.visible = true;
cnt2++;
}
cnt++;
}
}
I want to be able to catch clicks from radiobuttongroup controls, but can't get them to generate at all if with repeater or can't assign them id if with actionscript.
XML contents would look something like this:
<quiz>
<question>
<content>Some question?</content>
<answer>Answer one</answer>
<answer correct="true">Answer two</answer>
<answer>Answer three</answer>
<answer>Answer four</answer>
</question>
</quiz>
I'm having a hard time following what you are trying to do from your snippets, so here's a snippet of mine that should do exactly what your wanting. Hopefully you can review it and adapt it for your problem.
public function buildVBox():void{
tempVBox.removeAllChildren();
var iterator:Number = 0;
for each (var i:XML in myXML.children()){
var tempCanv:Canvas = new Canvas();
tempCanv.id = iterator.toString();
var tempRadYes:RadioButton = new RadioButton;
tempRadYes.x = 30;
tempRadYes.y = 20;
tempRadYes.origY = 20;
tempRadYes.groupName = "rbg" + iterator.toString();
tempRadYes.value = 1;
tempRadYes.label = "Yes"
tempCanv.addChild(tempRadYes);
var tempRadNo:extRadioButton = new extRadioButton;
tempRadNo.x = 80;
tempRadNo.y = 20;
tempRadNo.origY = 20;
tempRadNo.groupName = "rbg" + iterator.toString();
tempRadNo.value = 2;
tempRadNo.label = "No"
tempCanv.addChild(tempRadNo);
var tempRadNA:extRadioButton = new extRadioButton;
tempRadNA.x = 120;
tempRadNA.y = 20;
tempRadNA.origY = 20;
tempRadNA.groupName = "rbg" + iterator.toString();
tempRadNA.value = 0; tempRadNA.label = "N/A"
tempCanv.addChild(tempRadNA);
tempVBox.addChild(tempCanv);
iterator++;
}
}
Got a solution from here: http://www.jonathanrowny.com/journal/radiobuttongroup-inside-repeater

Flex AdvancedDataGrid - ColumnOrder With Formatter and ItemRenderer Question For Experts

I have a advanceddatagrid that has around 15 columns. Some are string,
some are numbers. I have shown 4 columns below.
The number columns have formatting done for zero precision and 2
digits precision. The itemRenderer is just to show Blue Color if the
number is +ve and Red Color if the number is -ve.
It looks something like below
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Name" textAlign"left"/>
<mx:AdvancedDataGridColumn dataField="Time" textAlign="right"/>
<mx:AdvancedDataGridColumn dataField="Score" textAlign="right" formatter="{zeroPrecisionFormatter}" sortable="true" itemRenderer="ColorRenderer" />
<mx:AdvancedDataGridColumn dataField="Average" textAlign="right" headerWordWrap="true" formatter="{twoPrecisionFormatter}" itemRenderer="ColorRenderer" />
...
I am trying to save the users setting of column order when he closes
the application and reload with the same order when the user opens the
applications. I am using SharedObjects and below is the code.
for(var i:int=0; i< adgrid.columns.length;i++){
var columnObject:Object = new Object();
columnObject.columnDataField = adgrid.columns[i].dataField as String;
columnObject.columnHeader =adgrid.columns[i].headerText as String;
columnObject.width = adgrid.columns[i].width;
columnArray.push(columnObject);
}
and then I save the columnArray to SharedObject.
I retrive them using the below code
for(var i:int=0;i<columnArray.length;i++){
adgrid.columns[i].dataField =columnArray[i].columnDataField;
adgrid.columns[i].headerText =columnArray[i].columnHeader;
adgrid.columns[i].width = columnArray[i].width;
}
How can I save and reload the Formatter and ItemRenderer data .
I am having trouble saving the formatter and itemrenderer and
reloading it again.
I would really appreciate if you can shown the code.
How can I reshuffle the columns but can preserve all the properties of it to though sharedobject and recover it again.
private function loadLayout(name:String="custom"):void {
var storedLayoutData:SharedObject;
storedLayoutData = SharedObject.getLocal("layouts");
if (storedLayoutData.data["pocketBankDG_"+name]) {
var columns:Array = new Array();
var index:int = 0;
for each (var column:Object in storedLayoutData.data["pocketBankDG_"+name]["columns"]) {
for ( var key:String in column) {
var propClass:Class = getDefinitionByName(column[key].propClassName) as Class;
adgOperations.columns[index][key] = column[key].propValue as propClass;
}
index++
}
} else {
saveLayout("default");
openSettingsWindow();
}
}
private function saveLayout(name:String="custom"):void {
var storedLayoutData:SharedObject;
storedLayoutData = SharedObject.getLocal("layouts");
if (!storedLayoutData.data["pocketBankDG"]) storedLayoutData.data["pocketBankDG_"+name] = new Object();
var columns:Array = new Array();
for each(var column:AdvancedDataGridColumn in adgOperations.columns) {
var describeType:XML = flash.utils.describeType(column);
var accessoriesList:XMLList = describeType..accessor;
var data:Object = new Object;
for each(var accessor:XML in accessoriesList) {
if (accessor.#access=="readwrite") {
var propClassName:String = getQualifiedClassName(column[accessor.#name]);
var propValue:* = column[accessor.#name];
if (propClassName=="String" || propClassName=="int" || propClassName=="Boolean" ||
propClassName=="Number" || propClassName=="uint") {
data[accessor.#name] = {}
data[accessor.#name].propClassName = propClassName;
data[accessor.#name].propValue = propValue;
}
}
}
columns.push(data);
}
storedLayoutData.data["pocketBankDG_"+name]["columns"] = columns;
storedLayoutData.flush();
}

Resources