Item renderer for dynamic DataGrid - actionscript-3

I have a problem with dynamic item renderer for data grids elements.
I'm initialiizng columns in my data grid dynamically, like this:
for each (var item in _collection)
{
var i:MyClass= item as MyClass;
var dgc:DataGridColumn = new DataGridColumn(i.Id.toString());
dgc.headerText = i.Name;
cols.push(dgc);
}
_myDataGrid.columns = cols;
To every cell I want to pass integer. When it has -1 value, cell should display specific text but when it's 0 or 1 it should contain checkbox.
Do you know how can I achieve that? I don't any ideas for now, despite I was thinking about this for quite long time. Can you help me with this?

Create itemRenderer with two states. One state with checkbox another with text

Related

Sort HTML emlements by child contents

I have these elements in a list. I want to sort the list alphabetically but how do i do that if the text that i want to sort it by is in a child element?
<div class="entry">
<button class="title btn btn-primary">Tale of Memories</button>
</div>
Without seeing your code, it is difficult to know exactly how things will work. Here is a generic solution:
Select all the elements in the list (eg: using querySelectorAll).
Transform the result of step 1 into an array (eg: with this solution from andrewmu)
Use the native sort() method to sort the array (providing your own function to compare values based on whatever you want).
Rewrite the content of the list with the content of the array.
Here is a demo. In it, we sort the list not based on the text directly in each item, but on the text from the span within each of them (for that reason the FA item goes first instead of last). In your case, you will want to change the compare function to get whichever element you want the items to be compared by:
// step 1: select the list items
var items = document.querySelectorAll("#mylist li");
// step 2: convert the node list into an array
var itemsarray = Array.prototype.slice.call(items, 0)
// step 3: sort the array using your own compare function
itemsarray.sort(function(a,b) {
return a.querySelector("span").innerHTML > b.querySelector("span").innerHTML;
});
// step 4: empty the list, and insert the sorted items
var ml = document.getElementById("mylist");
ml.innerHTML = "";
for (var x = 0; x < itemsarray.length; x++) {
ml.appendChild(itemsarray[x]);
}
<ul id="mylist">
<li><span>E</span></li>
<li><span>D</span></li>
<li><span>B</span></li>
<li>F<span>A</span></li>
<li><span>C</span></li>
</ul>

How to set textbox by value which get from each row of tablix?

If Datasource has 4 rows like these
___Item_____
AA
BB
CC
DD
If I make 10 textboxes
I need to input 4 value (AA,BB,CC and DD) to textboxes.
if some textbox isn't value, It will show (***)
like below .
1st row put to the first textbox.
2nd row put to the second textbox.
3rd row put to the third textbox.
4th row put to the fourth textbox.
and other put (***) because of Datasource has only 4 rows.
I mean I need to show free layout .I not mean horizontal tablix .
Because you wish to display the data in a fixed amount of textboxes and your dataset only has a single column, you shouldn't really try to fill the report dynamically. Instead of using an undefined datasource you could simply format the data and pass it as a list of parameters to the report.
ReportParameter[] reportParameters = new ReportParameter[10];
for (int i = 0; i < reportParameters.Length; i++)
{
reportParameters[i] = new ReportParameter(string.Format("pParam{0}", i),
(i < myDataSource.Count) ? myDataSource[i] : "***");
}
myViewer.LocalReport.SetParameters(reportParameters);
Then simply make sure you have parameters defined for the ones you are trying to display (e.g. pParam0 , pParam1, ... , pParam9) and add those in the wanted textboxes.

AS3/Flash: to fill textinput fields with datagrid row data

I'd like to know if it's possible to fill text fields by clicking on a data grid row, or by selecting a row and clicking a button "fill text fields".
Must be in AS3/Flash.
Thanks in advance.
I did try several aproaches and find a solution:
// import fl.events.ListEvent; <----- Important
toPrint.myGrid.addEventListener(ListEvent.ITEM_CLICK, onClick);
function onClick(e:ListEvent):void
{
var over = e.item;
// Fill the dynamic text fields
name.text = over.Name;
surname.text = over.Surname;
company.text = over.Company;
year.text = over.Year;
}
WorkS like a charm.

How do i populate an Array in one class based on a textfield in another class?(Actionscript 3.0)

i have a class (TheList.as). in which i have an array "Data" and it has a couple of values. Then i have a loop through which i am creating a scrollable list which uses the values from "Data" array. [I am trying make a unit converter]
Then i have another class "Units.as". In that class i have created three instances of "TheList". A main list ("myList"), and to sublists "ListFrom" and "ListTo". They are using values from "Data" array. Now i have text field whose value changes to whatever item is clicked. When i click "Angle" in the main list, i want the sublists to get populated with ("Degree", "Radian" etc)..
Here is what i tried
if(myList._TextLabel.text == "Angle")
{
ListFrom.Data = ["Degree", "Radian"];
}
But nothing happens, i do not get any error either. When i do this in an "ENTER_FRAME" event and trace (ListFrom.Data), i can see that the values change, but they do not get assigned to the list items in the list. I would really appreciate the help. Thanks!
Here are complete Classes for understanding the situation better(the code is pretty messy, as i am a newbie to OOP)
TheList.as: http://pastebin.com/FLy5QV9i
Units.as : http://pastebin.com/z2CcHZzC
where you call ListFrom.Data = ["Degree","Radian"], make sure when the data changed, the renders in the ListFrom have been set new data. for example, you may use MyRender in ListFrom for show, you should debug in the set data method in MyRender.
you should call the code below after you call ListFrom.Data = ["Degree","Radian"];
for (var i:int = 0; i < Data.legnth;i++) {
var render:MyRender = ListFrom[i] as MyRender;
if (render) {
render.data = Data[i];
} else {
var render:MyRender = new MyRender();
render.data = Data[i];
ListFrom.addChild(render);
}
}
You can use event listeners, singleton classes or reference one class to another, depending on the style you want. All are equally valid and fast / efficient.

Want to get cursor position within textInput

I am using textInput within grid using rendrer. I am populating a suggestion box just below the text input field on the basis of typed character and index of text input.Problem is that if i shrink grid column then suggestion box is not populating at the right place so I want global position of cursor in the text input field .
Something like that:
var inputTxt : TextInput = new TextInput;
var x : Number = inputTxt.cursorManager.currentCursorXOffset;
var y : Number = inputTxt.cursorManager.currentCursorYOffset;
Try using 'global coordinate'.
This might resolve your problem.