Reputation: 3
I create an AdvancedDataGrid with a HierarchicalData as DataProvider. Add my own itemEditor for the @value field in the DataProvider.
All works fine, if no value is set the background is set to red and the value to n/a but the replacement of the comma does not work. I'll be very happy if someone can help me with that problem.
Here is my MyItemEditor.as class:
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.TextInput;
public class MyItemEditor extends TextInput {
override public function set data(value : Object) : void {
if (value == null || value[DataGridListData(listData).dataField] == null)
return;
super.data = value;
if (String(value[DataGridListData(listData).dataField]).length == 0) {
setStyle("backgroundColor", "#FF0000");
value[DataGridListData(listData).dataField] = "n/a";
} else if (String(value[DataGridListData(listData).dataField]).indexOf(',') > -1) {
/** worked */
setStyle("backgroundColor", "#FFFF00");
/** does not work */
//value[DataGridListData(listData).dataField].replace(',', '.');
//String(value[DataGridListData(listData).dataField]).replace(',', '.');
//value[DataGridListData(listData).dataField].replace(/,/, '.');
String(value[DataGridListData(listData).dataField]).replace(/,/, '.');
} else {
setStyle("backgroundColor", "#FFFFFF");
}
}
}
And my Test.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init_data()">
<mx:Script>
<![CDATA[
import mx.collections.HierarchicalData;
[Bindable] private var xmlData : XMLList;
[Bindable] private var xmlDP : HierarchicalData;
private function init_data() : void {
xmlData =<>
<item name="Project 1">
<valuetype name="Spannung" value="5" unit="V" />
<valuetype name="Widerstand" value="500" unit="Ohm" />
<valuetype name="Stromstaerke" value="0,01" unit="A" />
</item></>;
xmlDP = new HierarchicalData(xmlData);
}
]]>
</mx:Script>
<mx:HBox width="100%" height="100%">
<mx:AdvancedDataGrid
id="dataGrid"
height="100%"
width="75%"
rowHeight="25"
dataProvider="{xmlDP}"
folderClosedIcon="{null}"
folderOpenIcon="{null}"
defaultLeafIcon="{null}"
editable="true"
draggableColumns="false">
<mx:groupedColumns>
<mx:AdvancedDataGridColumn
editable="false"
headerText="Name"
dataField="@name"
minWidth="500"/>
<mx:AdvancedDataGridColumn
editable="true"
headerText="Wert"
dataField="@value"
minWidth="125"
rendererIsEditor="true"/>
<mx:AdvancedDataGridColumn
editable="false"
headerText="Einheit"
dataField="@unit"
minWidth="125"/>
</mx:groupedColumns>
<mx:rendererProviders>
<mx:AdvancedDataGridRendererProvider
depth="2"
columnIndex="1"
columnSpan="1"
renderer="MyItemEditor"/>
</mx:rendererProviders>
</mx:AdvancedDataGrid>
<mx:Tree id="dataTree" defaultLeafIcon="{null}"
dataProvider="{XML(xmlData).children()}"
labelField="@value" height="100%" width="25%"/>
</mx:HBox>
The tree is to check if the values was set. Some times the value will not be set the first time. Ist also a little strange.
Upvotes: 0
Views: 324
Reputation: 7311
In Flex (as in most of the modern languages), the strings are immutable. The replace()
method does not alter the string on which it is applied, but it creates a new String that holds the result.
result = original.replace(',', '.');
Upvotes: 0