I am creating a Datagrid dynamically in AS3. In MXML it is valid to write:
mx:DataGridColumn dataField="abc" id="testColumn"
in AS3 however, I can not use the property "id", it is not found. Any ideas?
var dgc : DataGridColumn = new DataGridColumn();
dgc.id = "testColumn"; (NOT WORKING)
Thanks,
martin
The id is not a real property, but only a way to define the variable name in mxml. Therefore in your case the ID is "dgc".
What are you trying to achieve, by the way?
Related
I am using datagrid with inline editor which have validatebox, numberbox, and combobox. What I am try to do is when I select the combobox, I need to set numberbox prefix as currency symbol as I want. If I want to set the value to the numberbox, usually write like this:
var ed8 = $("#dg").datagrid("getEditor", {index:idx, field:'cost'});
$(ed8.target).numberbox('setValue',value);
but I am stack on case how to change/set the property "prefix" of numberbox.
One more thing that I want to ask, Is that possible to set multiple prefix in one field (one row one prefix) of datagrid?
I just found the solution by put the code like this.
var ed8 = $("#dg").datagrid("getEditor", {index:idx, field:'cost'});
var opts = $(ed8.target).numberbox('options');
opts.prefix = '$';
It is possible to set multiple prefix on a field
hope this can help others.
I create each datagrid to be added to the NavigatorConent(), however, how do I retrieve the datagrid by ID so that I can point the ArrayCollection to datagrid's dataprovider?
private var pdg:String;
private function stabAdd():void {
var dg1:DataGrid = new DataGrid();
var cn:NavigatorContent = new NavigatorContent();
stab.addElement(cn);
cn.name = "nc"+nu;
dg1.id = "nc"+nu;
pdg = dg1.id;
dg1.addEventListener(MouseEvent.CLICK,cc);
nu++;
This will throw an error which pdg cannot be found, I wonder why:
trace(DataGrid(pdg));
The purpose of nu++ is to assign a
unique name (dg1, dg2, etc) to each
datagrid so that I can assign AC to
that datagrid's dataprovider
I can respect the need to give every component a unique name. The appropriate way to do that in ActionScript is not to specify the id/name field of the component, but rather to create an instance of the component as a variable. Something like this:
protected var myGrid : DataGrid;
And you can now access myGrid anywhere in the component, or in it's children, without creating some complicated scheme. If you need multiple DataGrid's you can store them in an array:
protected var myGridArray : Array = new Array();
And somewhere later in your code--probably createChildren() do something like this:
loop
var newGrid : DataGrid = new DataGrid()
myGridArray.push(newGrid);
end loop
For the most part, this is how all the Flex list based components do it with itemRenderers. They have an array of visible renderers.
As stated in #J_A_X_ comments, you are trying to convert pdg--a string--into a DataGrid. I would expect that to return a null value, as Flex casts tend to fail quietly.
If you want more help, you'll have to tell us the explicit error that you're receiving, possibly with line numbers and more code.
I am trying to find a way bind Grid view to a JSON.NET parsed Linq to Json object
simply am calling
JObject yrs = SearchData("");
then use one property to be bound to Grid view
GridView1.DataSource = yrs["businesses"].Children();
I cant find any resources for something like that
neither binding directly work nor using Children, and seems like I can not find it in the documentation.
appreciate your help
I think I just needed to sleep :)
this is how it should go, if someone need that ,
var bsn =from c in yrs["businesses"].Children()
select new { Title = (string)c["Title"] , Type = (string)c["Type"] };
GridView1.DataSource = bsn;
if there are better ways please advice
Acctually
I want to remove Child from VBox , i have id of child , but i don't to have real object that i want to remove using removeChild function of VBox
var elem:Type_of_E = this["constructed_id_of_E"];
If you have the id of the child to be removed, you have the real object. id attribute in mxml creates a public variable by it's value and store a reference to the object in that variable.
if(childId != null)
vbox.removeChild(childId);
else
trace("Normally this shouldn't happen in flex");
//or if you don't have VBox's id but you are sure that
//the child is in fact is parented by a container:
childId.parent.removeChild(childId);
Assuming you know the name of your VBOX before runtime:
yourVBOX.removeChild( yourVBOX.getChildByName('yourChildID') );
Read more on:
LiveDocs - Container - getChildByName
You might also want to set the "name" property on your component, such as :
myLabel.name = "LabelX";
myLabel.id = "LabelX"; // eventually
Then proceed to doing as the first answer said,
yourVBOX.removeChild( yourVBOX.getChildByName('LabelX') );
The thing to remember is to set the name as well as the ID, there is no such method as "getChildByID" :-)
getChildByID:
this.getChildren()[id]
I have a script that parses some complex XML. When the XML element is of a certain type, it generates a comboBox using the XML element's children to populate the box. I then want to check all of the values of the all the generated ComboBoxes against their correct answers (which is also info stored in the XML file). When creating the ComboBoxes, I added an "id" property. However, it seems that I cannot them use:
dynamicQuestion.id.selectedItem.labelField
to check the answers. However, I am able to get the labelField if I know the variable name used to create the ComboBox.
dynamicQuestion.selectedItem.labelField
This indicates (to me) that I need to dynamically generate the variable name as I'm creating new instances of the ComboBox. But how do I dynamically generate a variable name? If I use
var thisBox:String = "box"+boxCount;
var newBox:ComboBox = thisBox as ComboBox;
I get an implicit coercion error. I also tried changing the creation statement to a function that accepted an argument, "thisBox," but this didn't work either. Conceptually, this seems quite simple, but I'm having a hard time putting it to practice. It seems that the comboBox's id is what is generated by created the box using script (e.g., var thisBox). How do I dynamically generate this name?
Use an array as Stefan suggested. If you must use string identifiers, you can create an object and use it as an associative array.
var combos:Object = {};
var boxCount:Number = 1;
var thisBox:String = "box"+boxCount;
//you can store comboboxes in the object using the following syntax
combos[thisBox] = new ComboBox();
//or
combos.box2 = new ComboBox();
//or
combos["box3"] = new ComboBox();
trace(combos.box1.selectedItem.labelField);
trace(combos.box2.selectedItem.labelField);
trace(combos.box3.selectedItem.labelField);
Why don't you store all your dynamically created combo boxes in an array? When you want to evaluate them you iterate over the array and access selectedItem.labelField.