I have one datgrid with no. of columns like:
<s:DataGrid id="cpDataGrid" dataProvider="{arrList}">
<s:columns>
<mx:ArrayList>
<mx:source>
<s:GridColumn headerText="Name" dataField="name" editable="false"/>
<s:GridColumn headerText="Age" datafield="age" editable="false"/>
<s:GridColumn headerText="Test" dataField="test" editable="false" />
<s:GridColumn width="100" headerText="Result" dataField="result" >
</mx:source>
</mx:ArrayList>
</s:columns>
</s:DataGrid>
In the above datagrid result column is editable. I have make function when user done entering value in that column as following:
protected function onCreationCompleteHandler(event:FlexEvent):void
{
cpDataGrid.addEventListener(GridItemEditorEvent.GRID_ITEM_EDITOR_SESSION_SAVE, onSave);
}
private function onSave(event:GridItemEditorEvent):void
{
var name:String = event.currentTarget.selectedItem.name;
}
Now, I will get name and other field value when edit end. But i need Result text. Means Whatever user entered text in that field.
Like suppose user enter 50 in result column then how can i got that value?
Any help will greatly appreciated.
For spark.DataGrid you need to create custom class based on spark.DataGrid and override method endItemEditorSession. In it you can access DataGrid's property itemEditorInstance.
If you would use mx.DataGrid, you could use DataGridEvent.ITEM_EDIT_END event in combination with itemEditorInstance property of DataGrid.
// register listener
cpDataGrid.addEventListener(DataGridEvent.ITEM_EDIT_END, onItemEditEnd);
...
// listener
private function onItemEditEnd(event:DataGridEvent):void {
// at this point itemEditorInstance is still available, so you can get entered value from it
// if itemEditorInstance is TextInput
var enteredValue:String = TextInput(cpDataGrid.itemEditorInstance).text;
}
Related
I have datefield in DataGrid GridColumn like following:
<s:GridColumn headerText="Date" dataField="newDate" rendererIsEditable="true">
<s:itemRenderer>
<fx:Component>
<s:GridItemRenderer>
<mx:DateField id="dtNewDate" selectedDate="{new Date()}"/>
</s:GridItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:GridColumn>
Now want dtNewDate selectedValue then how can get that. If i get datafield value of gridColumn i.e. newDate but there is nothing.
So, how can i get new selected value of DateField?
Edit:
dg.addEventListener(GridItemEditorEvent.GRID_ITEM_EDITOR_SESSION_SAVE, onSave);
private function onSave(event:GridItemEditorEvent):void
{
// I want datefield value here.
}
To get the new selected date, you can simply use the change event on your DateField control :
<mx:DateField id="date" change="on_date_change(event)"/>
And
protected function on_date_change(e:CalendarLayoutChangeEvent):void
{
var selected_date:Date = e.currentTarget.selectedDate;
var date:String = selected_date.getFullYear().toString()
+ '/' + (selected_date.getMonth()+1).toString()
+ '/' + selected_date.getDate();
trace(date); // gives for example : 2015/12/31
}
Hope that can help.
I coded the following in Flex 4/AS3 and it doesn't worked as expected.
So, I would like to know if there is something wrong with my code... I'll explain it:
TileTest.mxml
<s:Application minWidth="955" minHeight="600" creationComplete="createButtons()"
<fx:Script>
<![CDATA[
import Object.TestButton;
import mx.collections.ArrayList;
private var _names:Array = ["one", "two", "three"];
public function createButtons():void
{
var buttons:ArrayList = new ArrayList();
for(var a:int = 0; a < _names.length; a++)
{
var testButton:TestButton = new TestButton();
testButton.customName = _names[a];
buttons.addItem(testButton);
}
myList.dataProvider = buttons;
}
]]>
</fx:Script>
<s:VGroup gap="12" width="100%">
<s:Label text="Options" fontSize="18" fontWeight="bold" color="#333333" />
<s:List width="100%" height="100%" id="myList" itemRenderer="Object.TestButton" borderVisible="false">
<s:layout>
<s:TileLayout orientation="rows" columnWidth="290" rowHeight="90" columnAlign="left" horizontalGap="0" verticalGap="0" />
</s:layout>
</s:List>
</s:VGroup>
</s:Application>
This is my Application. Here, I have a List called myList, where I load some TestButtons. I set a name for each button inside the loop.
TestButton
<s:Group width="300" height="90" click="{ Alert.show(_name); }"
<fx:Script>
<![CDATA[
import mx.controls.Alert;
private var _name:String = "just a test...";
public function set customName(newName:String):void
{
_name = newName;
Alert.show(_name);
this.addEventListener(MouseEvent.MOUSE_OVER, function():void{ Alert.show(_name); });
}
]]>
</fx:Script>
<s:BorderContainer accentColor="#000000" width="100%" height="100%" />
</s:Group>
As you can see, I have three Alerts in this component... I did so we can understand the problem.
The first Alert occurs when I set the customName, which occurs in the Application, as already shown.
The second one should occur on Mouse_Over, as the event listener been added to the Group element.
And the third Alert should occur on Click in the Group element.
Now, if I run the resulting swf, I see all the three buttons in the screen and three Alerts, one for each set customName by the Application and it alerts the right name.
If I put the mouse over any button, it doesn't alert any message.
If I click any button, it alerts the default message set to the _name property, which is "just a test..."
I can't understand what is the problem, as I was expecting it to always alert the name set by the Application to each button. Also, I don't want to change the components... what I'm saying is that I would like to have a List and TestButtons with a private String inside.
If the problem is in these specific implementation, so I'll have no other way than change it...
Thank you all!
The problem is that you have a list of TestButtons in your data provider, instead of just plain data. Those buttons get created, and that is why you see the correct Alert messages.
So, then Flex sees a list with three items and therefore it creates three additional TestButtons to render the data in your list. But those TestButtons are completely new ones, with default values for its properties.
To fix this, it would be better if you had data only in your data provider ArrayList, and you would access it through the data property of your item renderer.
hi so this is my first flash application i have two functions one a click handler to take you to the list page and a function to call the results is there any way in actionscript to pass values through variables like in php($)
what i need to do is to set the function off from the button that is pressed every button needs to supply a different value to the list to get results heres the two functions
protected function button_clickHandler_100():void
{
currentState='data';
}
protected function dataGrid_creationCompleteHandler(event:FlexEvent):void
{
getCitysResult.token = cityservice.getCitys(/* VALUE ENTERED HERE */);
}
<s:Button click="button_clickHandler_100()" id="button128" includeIn="europe" skinClass="components.englandButton" x="101" y="135"/>
<s:Button click="button_clickHandler_100()" id="button129" includeIn="europe" skinClass="components.denmarkButton" x="135" y="117"/>
<s:Button click="button_clickHandler_100()" id="button130" includeIn="europe" skinClass="components.polandButton" x="214" y="135"/>
<mx:DataGrid includeIn="data" x="28" y="10" id="dataGrid" creationComplete="dataGrid_creationCompleteHandler(event)" dataProvider="{getCitysResult.lastResult}" width="276" height="255">
<mx:columns>
<mx:DataGridColumn headerText="city" dataField="city"/>
</mx:columns>
</mx:DataGrid>
so for instance the vlaue that needs to be supplied is GB for button128 , PL for button130 ....
getCitys returns a list of citys and populates a datagrid according to a 2 letter code it is a php sevice
is there a way i could get the clickHandler to supply the value to getCitys function according to which button is pressed off the id of the button say
I'm working on a flex project, and have a datagrid that I'd like the cursor to change when hovering over any row containing data.
I have double click enable on the datagrid and I'd like to indicate to the use that they can click the row they are hovering over.
This is what I've tried but it seems to just use the hand cursor on the datagrid its self and not the row data.
<mx:DataGrid x="9" y="47" width="330" height="244" useHandCursor="true" buttonMode="true" mouseChildren="true" horizontalScrollPolicy="{ScrollPolicy.AUTO}" styleName="resultgrid" dataProvider="{acLatest}" doubleClickEnabled="true" itemDoubleClick="doubleClickoverview()" id="overviewLatest_dg">
<mx:columns>
<mx:DataGridColumn headerText="Tag" id="overviewLatest_dg_animal_ptag" visible="true" dataField="animal_ptag" width="110" />
<mx:DataGridColumn headerText="Status" id="overviewLatest_dg_status_status" visible="true" dataField="status_status" width="110"/>
<mx:DataGridColumn headerText="Sex" id="overviewLatest_dg_animal_sex" visible="true" dataField="animal_sex" width="110"/>
</mx:columns>
</mx:DataGrid>
I would create an itemRenderer and add event listeners for the MouseEvent.ROLL_OVER and MouseEvent.ROLL_OUT events. In the event handlers you can change the cursor using the cursorManager. This also has the added benefit of allowing you to change the cursor based on some data or condition for the row the user is hovering their cursor over.
Here's an example on changing the cursor when mousing over a component. Hopefully this gets you started in the right direction.
Ended up using itemRollOver & itemRollOut on the datagrid.
Then just created a simple class that changes the cursor to a hand image.
DataGrid:
itemRollOver="Cursors.setHandCursor()" itemRollOut="CursorManager.removeAllCursors()"
Cursor Class:
package com {
import mx.managers.CursorManager;
import mx.managers.CursorManagerPriority;
public class Cursors extends CursorManager {
private static var handCursorList:Array = [];
public static function setHandCursor():void {
[Embed(source="../images/hand.png")]
var handCursorClass:Class;
handCursorList.push(setCursor(handCursorClass, CursorManagerPriority.MEDIUM));
}
}
}
I'm using a data grid with an item renderer that creates a toggle button. The idea is to have a list of items and only allow one to be selected and pre-select one at start.
I've got the single button selection working, meaning that when I click on on toggle button, the others are deselected.
My problem is to create a way of pre-selecting an element of the data grid or simulate a click on a row and selecting the corresponding toggle button.
If I use the datagrid.selectedIndex the result is a selection but the toggle button doesn't get selected.
Here is the code example
In this example I am using the array value "selected" to define selected button, not my favourite solution but the one that worked first.
The array collection:
public static const ValuesList : ArrayCollection = new ArrayCollection(
[
{ID:0, Name:"One", selected:false},
{ID:1, Name:"Two", selected:false},
{ID:2, Name:"Three", selected:false},
{ID:3, Name:"Four", selected:false}
]
);
The data grid:
<s:DataGrid id="dataGrid" dataProvider={ValuesList} >
<s:columns>
<s:ArrayList>
<s:GridColumn id="GridCol0" />
<s:GridColumn id="GridCol1" />
<s:GridColumn id="GridCol2" itemRenderer = "detail_ItemRenderer" />
</s:ArrayList>
</s:columns>
</s:DataGrid>
The column item renderer:
<?xml version="1.0" encoding="utf-8"?>
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
clipAndEnableScrolling="true">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
/**
* Creatioon complete event handler to set toggle button content value.
* */
protected function MyToggleButton_creationCompleteHandler(event:FlexEvent) : void
{
MyListToggleButton.label = data.Name;
MyToggleButton.selected = data.selected;
}
/**
* One of the only function that are called on item interaction.
* */
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth,unscaledHeight);
MyToggleButton.selected = data.selected;
}
]]>
</fx:Script>
<s:ToggleButton id="MyToggleButton" width="100%" height="100%"
creationComplete="MyToggleButton_creationCompleteHandler(event)" />
</s:GridItemRenderer>
SOLUTION:
Using the data array to pass information into the Toggle button. Setting one value to "true" will display the selected element.
To insure data integrity I advise to set the selected index of the grid to the corresponding index of the value set to "true":
public function SetSelectedIndexByName() : int
{
for (var i : int=0; i < dataGrid.dataProvider.length ; i++)
{
if (dataGrid.dataProvider[i].toString().toUpperCase() == "TRUE")
{
return i;
}
}
return -1;
}
In your GridItemRenderer, you should overwrite the setter of data. Your data will contain a variable defining the selection of the ToggleButton. In the setter you will be able to toggle the button based on this variable.
To have only one button selected, you may use a static variable in your renderer which stores the selected itemrenderer. This one is simpler but not really clean since it's a matter of data, not renderers. So you may listen for any change in the dataProvider from a higher level and ensure there's only one item selected.