Editable Datagrid with LabelFunction Problems
Hi,
I'm having problems with a datagrid with editable columns and labelFunctions.
The problem is that when i leave the editable field by a way that wasnt with Escape Key, the datagrid apply again the labelFunction and destroy the number formattion adding a lot of numbers.
When the field is filled with 0000,00 he just adds more zeros, like 0.000.000,0000 and keep going after do the same process.
And when the field has a number different of zero, he apply the labelFunction then after he remove the labelFunction. After few times it just make the number vanish and the cell goes empty.
I read the documentation about editing cell and tryed to implement a solution to prevent the cell be edited, without sucess.
The source code goes attached for some advice on my problem.
Thanks, Fredy.
Hi,
I solved a part of problem with some changes that i've made.
Now there is no problem with values different of zero, when i got just number, its fine, but still have problems with zero values.
The snippet code goes next, the bold part that was modified from the last sample.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.DataGridEventReason;
import mx.controls.TextInput;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.formatters.NumberFormatter;
import mx.events.DataGridEvent;
import mx.collections.ArrayCollection;
[Bindable] private var collection:ArrayCollection = new ArrayCollection([
{code:1, description:"Item 1", value:4564654},
{code:2, description:"Item 2", value:00000000},
{code:3, description:"Item 3", value:00000000},
{code:4, description:"Item 4", value:00000000},
{code:5, description:"Item 5", value:00000000},
{code:6, description:"Item 6", value:00000000},
{code:7, description:"Item 7", value:00000000}
private var formatter:NumberFormatter;
private function formatterFunction(item:Object, column:DataGridColumn):String {
if (formatter == null){
formatter = new NumberFormatter();
formatter.decimalSeparatorTo = ",";
formatter.thousandsSeparatorTo = ".";
formatter.decimalSeparatorFrom = ",";
formatter.thousandsSeparatorFrom = ".";
formatter.useThousandsSeparator = true;
formatter.precision = 4;
return formatter.format(item[column.dataField]);
private function editEndHandler(event:DataGridEvent):void {
var myEditor:TextInput = TextInput(event.currentTarget.itemEditorInstance);
var newVal:Number = isNaN(Number(myEditor.text)) ? myEditor.text as Number : 0.0000;
var oldVal:Number = Number(event.currentTarget.editedItemRenderer.data[event.dataField]);
// it solves the partial part of the problem, but still have some errors
if (event.reason == DataGridEventReason.CANCELLED || event.reason == DataGridEventReason.OTHER) {
return;
if (oldVal == newVal ) {
// i've tryed this, but the itemEditor still open
event.preventDefault();
// if I just put 'return', still have the same problem
// return;
]]>
</mx:Script>
<mx:Label text="Bug datagrid editavel com labelFunction"
fontSize="16"
fontWeight="bold" />
<mx:DataGrid dataProvider="{collection}"
editable="true"
itemEditEnd="editEndHandler(event)">
<mx:columns>
<mx:DataGridColumn headerText="Código"
dataField="code"
editable="false"/>
<mx:DataGridColumn headerText="Descrição"
dataField="description"
editable="false"/>
<mx:DataGridColumn headerText="Valor"
width="300"
dataField="value"
labelFunction="formatterFunction"
editable="true"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
@Alex
Thanks for the answer.
I want to edit this column, but if there is no 'change' i dont want to apply again the label function and close the itemEditor.
I've tryed to call event.preventDefault() but i dont know what to do next.
Do you have some advice how to solve my problem?
This is just happening when i got zero values on my datagrid =/
Thanks all for the answers.
Similar Messages
-
Editable DataGrid With DateField
I'm new to flex and struggling with the editable DataGrid. I
have a DataGrid with an ItemRenderer that outputs a DateField. I
can't figure out how to get the new value of the DateField after
the edit.
Here is my DataGrid (the endDate column):
<mx:DataGrid id="allHistoryGrid"
dataProvider="{allEntries}" height="313" width="782" y="-4"
itemEditEnd="saveGridChange(event)" editable="true">
<mx:columns>
<mx:Array>
<mx:DataGridColumn dataField="dietDescription"
headerText="Diet"/>
<mx:DataGridColumn dataField="allergyDescription"
headerText="Allergy"/>
<mx:DataGridColumn dataField="labDescription"
headerText="Lab"/>
<mx:DataGridColumn dataField="labResult" width="50"
headerText="Result" itemRenderer="LabResultItemRenderer"/>
<mx:DataGridColumn dataField="medicationDescription"
headerText="Medication"/>
<mx:DataGridColumn dataField="height" width="65"
headerText="Height" itemRenderer="HeightItemRenderer"/>
<mx:DataGridColumn dataField="weight" headerText="Weight"
itemRenderer="WeightItemRenderer"/>
<mx:DataGridColumn dataField="bmi" width="35"
headerText="BMI" itemRenderer="BmiItemRenderer"/>
<mx:DataGridColumn dataField="circumference" width="45"
headerText="Circ." itemRenderer="CircumferenceItemRenderer"/>
<mx:DataGridColumn headerText="Start Date" width="75"
sortCompareFunction="startDateSortCompare">
<mx:itemRenderer>
<mx:Component>
<mx:VBox clipContent="false">
<mx:DateFormatter id="dateFormatter"
formatString="MM/DD/YYYY"/>
<mx:Text width="100"
text="{dateFormatter.format(data.startDate)}"/>
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="endDate" width="45"
headerText="End Date" itemRenderer="EndDateItemRenderer"
rendererIsEditor="true"/>
<mx:DataGridColumn id="deleteEntry" width="50"
textAlign="center"
headerText="Delete" sortable="false"
itemRenderer="DeleteItemRenderer"/>
</mx:Array>
</mx:columns>
</mx:DataGrid>
Here is my itemRenderer:
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="
http://www.adobe.com/2006/mxml"
paddingLeft="16" horizontalAlign="center">
<mx:DateFormatter id="dateFormatter"
formatString="MM/DD/YYYY"/>
<mx:DateField x="16" y="67" id="AllHistoryEndDate"
text="{dateFormatter.format(data.endDate)}"/>
</mx:VBox>
How do I get the new value in the saveGridChange function?
private function saveGridChange(event:DataGridEvent):void {That gives me this error:
TypeError: Error #1034: Type Coercion failed: cannot convert
EndDateItemRenderer@51a70a1 to mx.controls.TextInput. -
Datagrid with textfield problem
Hello,
I have a datagrid with a custom cellrenderer that renders the datagrid column as a textfield. This works fine, but when I scroll the datagrid up and down, the text in the text field gets all jumbled. I have attached an image showing before and after scrolling. I am assuming that I need to redraw the datagrid after the scrollbar loses focus or something like that, but I am new to AS3 and unsure how to proceed. Any help greatly appreciated!The phone can deal with that. It's just how the input system of most phones work: a sentence starts with a captical letter. you can simply turn that of, just as you would so if you were writing an sms. See your phones manual for that!
-
Editable datagrid firefox problem
I have created an application that contains an editable
datagrid but experiences problems when using the firefox browser.
If there are multiple tabs of firefox open and an item is selected
in the grid, when switching between the firefox tabs, the datafield
in the grid becomes selected for edit without clicking on it. It
appears that some kind of event is being called to change an entry
in the grid. Similar results occur when changing between different
windows i.e. firefox and flex builder.
However, I don't have this problem when using internet
explorer.That should be true for any Flex component. Focus is always on something, you have to move it to a new place otherwise it gets restored back to what last had foucs.
Alex Harui
Flex SDK Developer
Adobe Systems Inc.
Blog: http://blogs.adobe.com/aharui -
Editable Datagrid from programmaticaly built XmlListCollection help needed
Hi, I am trying to build an editable datagrid with 20 empty
rows in it. Users will fill out the cells, this then gets persisted
to a DB, then later by making selections in a combobox, they can
bring this data back for viewing and/or modification. I have been
trying to create the XML dynamically and then addItem on the
XmlListCollection to no avail. Can someone please point out where I
am going wrong? Thanks!
[Bindable] private var teamGridDataAsXml:XML;
[Bindable] private var teamGridData:XMLListCollection;
private function initEmptyTeamGrid():void {
teamGridData = new XMLListCollection();
var s:String = "<rows>";
for(var i:int = 0; i < 20; i++) {
s += "<row rowIndex=\'" + i + "\' agentId='' firstName=''
lastName='' country='' />";
s += "</rows>";
teamGridDataAsXml = new XML(s);
teamGridData.addItem(teamGridDataAsXml);
<mx:DataGrid id="agentInfo" editable="true"
dataProvider="{teamGridData}" width="100%" height="100%"
rowCount="20">
<mx:columns>
<mx:DataGridColumn headerText="#" dataField="@rowIndex"
editable="false"/>
<mx:DataGridColumn headerText="Agent ID"
dataField="@agentId" editable="true"/>
<mx:DataGridColumn headerText="First Name"
dataField="@firstName" editable="true"/>
<mx:DataGridColumn headerText="Last Name"
dataField="@lastName" editable="true"/>
<mx:DataGridColumn headerText="Country"
dataField="@country" editable="true"/>
</mx:columns>
</mx:DataGrid>teamGridDataAsXml = new XML(s);
trace(teamGridDataAsXml.toXMLString() ); to be sure you have
good xml
var xlRows:XMLList = teamGridDataAsXml.row;
trace(xlRows.length()); //what you expect?
teamGridData =new XMLListCOllection(xlRows);
You could skip the xml variable and go straignt into the
XMLListCollection also. In the loop, build the XML node, using XML
literal syntax, and then call addItem *inside the loop*.
Tracy -
I've been using Elements 10 on my windows 7 machine editing RAW/NEF picture files taken with a Nikon D40X camera with no problems. I upgraded my camera to a Nikon DX7100 and can no longer load my RAW/NEF into elements 10. Is there a compatability problem with my new camera? Will upgrading elements to a newqer version solve the problem?
NEF's for the D7100 should work with the latest version PSE13
You can download here and try free for 30 days:
https://www.adobe.com/cfusion/tdrc/index.cfm?product=photoshop_elements&loc=us&PID=2159997 # -
I can not get my Adobe Photoshop Elements 8 organize to open. The edit option comes up with no problem, but will crash when I try to access organize. What should I do to fix this problem?
Hi,
Which operating system are you running on?
Try starting the organizer while holding down the shift key. Hopefully, it should load the Catalog Manager.
Select your current catalog and click on the Repair button. Once it has finished, click on the Open button to see if the catalog opens.
Good luck,
Brian -
Have purchased a new computer but can not install elements 12 since it has been installed on an older laptop. This is a one time user program, is there a code that can be put in or a small fee to pay to be able to use the program again. Never installed the video editing and hoping this can be installed with no problem.
If the laptop is still connected Launch Elements in Expert Mode. Go to the help menu and sign-out. That will deactivate usage on the laptop.
-
Problem with labelfunction with checkbox itemrenderer
I have a DataGrid with a column that looks like this:
<mx:DataGridColumn headerText="Buy online?"
dataField="onlineshop" itemRenderer="mx.controls.CheckBox"
rendererIsEditor="true" labelFunction="checkBoxLabel"
editorDataField="selected" />
My label function looks like this (for testing):
private function checkBoxLabel(item:Object,
column:Object):Boolean
return false;
The checkboxes in the grid always show up checked by default.
What am I doing wrong?"endquote" <[email protected]> wrote in
message
news:e4e0cj$ffh$[email protected]..
>I have a DataGrid with a column that looks like this:
>
> <mx:DataGridColumn headerText="Buy online?"
dataField="onlineshop"
> itemRenderer="mx.controls.CheckBox"
rendererIsEditor="true"
> labelFunction="checkBoxLabel" editorDataField="selected"
/>
>
> My label function looks like this (for testing):
>
> private function checkBoxLabel(item:Object,
column:Object):Boolean
> {
> return false;
> }
>
> The checkboxes in the grid always show up checked by
default. What am I
> doing
> wrong?
labelFunction is for the *label* (of the CheckBox, in this
case). The
selected property of the CheckBox is set based on the value
of the
dataField--in your case, "onlineshop". Is onlineshop true in
all your items?
Manish Jethani
Developer, Flex Framework
Adobe Systems Inc. -
Problem filling DataGrid with XML - Object or ArrayCollection?
Hi,
I am trying to fill a datagrid with an XML file, rendered
from a PHP
script.
The problem is that - first time there is only one entry in
the XML
file, so when I receive the data using
event.result.root.child, I get
an Object. But second time, when there are two entries in the
XML
file, the return type becomes an ArrayCollection of "child"
type
objects.
This causes a problem when setting dataprovider of a
DataGrid....
So is there a way I can know what is the return type from the
XML
file, i.e., whether it is an Object or an ArrayCollection, so
that I
can set the dataprovider accordingly?In E4x
If you have an xml structure like so:
<parent prop1='someValue' >
<child prop1='someValue' />
</parent>
to reference the parent use event.result
to get the child use: event.result.child; to get the child
attr: event.result.child.@prop1; -
Strange Behaviour on DataGrid with ArrayCollection as DataProvider
I have a Datagrid with an ArrayCollection as DataProvider, the arrayCollection is partially generated by a remoteObject call, the dataprovider seems to works at least until I try to edit the field...
By the RemoteObject I only receive an ArrayCollection with the field `ip`, but the datagrid looks for the fields ip, check and save...
If I add/edit this new field it works, but only under particular condition
The DataGrid:
<s:DataGrid id="datagrid" left="10" right="10" top="136"
dataProvider="{listaIPCheck}" bottom="10" requestedRowCount="4">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="ip" headerText="Asset"/>
<s:GridColumn dataField="check" headerText="Inventory"/>
<s:GridColumn dataField="save" headerText="Salvataggio"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
The Script:
[Bindable]private var listaIPCheck:ArrayCollection;
private function ro_resultHandler(event:Event=null):void
listaIPCheck = new ArrayCollection();
listaIPCheck = ro.getListUpdate.lastResult;
heap = 0;
// Read Below {POINT #1}
init3();
private function init3():void
// Read Below {POINT #2}
if (heap<listaIPCheck.length)
// omitted the initialization of the process p
p.addEventListener(NativeProcessExitEvent.EXIT, onExit);
try{
p.start(startupInfo);
}catch(e:Error){}
private function onExit(e:NativeProcessExitEvent):void {
// Read below {POINT #3}
Here is my code, now as you can see there are 3 line where I wrote to read below...
Let's assume to put this simple `for` instead of the commented line (once at a time)
for (var k:Number=0;k<listaIPCheck.length;k++)
listaIPCheck.getItemAt(k).check = "checkVal";
listaIPCheck.getItemAt(k).save = "saveVal";
This code always work in the 3 points, so at the end of the call the ArrayCollection is always filled with the new values, but the datagrid refresh the items only in POINT #1 and POINT #2
Why not in Point #3???Thank you Amy, but adding the properties in the server side did not work...
The workflow of the program is that:
1) I get the ArrayCollection (listaIPCheck) contatining some information (function ro_resultHandler)
2) I start an external process and grab the output data (function init3)
3) read and use the data from the process (function onExit)
Now the problem I have is regarding the refresh of the datagrid, this datagrid has the ArrayCollection (listaIPCheck) as DataProvider.
So:
- If I put the for loop instead of the comments ( // Read Below {POINT #1} ) or
( // Read Below {POINT #2} ) it works, the ArrayCollection is updated and the datagrid is refreshed
- Whereas if I put the for loop instead of ( // Read Below {POINT #3} ) , it won't work.. or at least, the ArrayCollection is correctly updated, but the datagrid is not refreshed at all and I have to use .refresh() -
Formatting a field before committing from editable datagrid
Hi,
I have an editable DataGrid which displays two columns, date
and value. Now, the date in the dataProvider is actually stored as
an integer (yyyymmdd) so I format it using a labelFunction to
display. I then have a custom itemEditor to set it to a date for
calling into the DateField.
The next step, and where I'm struggling, is to update the
dataProvider with an integer (yyyymmdd) calculated from the
selectedDate. Can someone please help me with how to do this?
Thanks!See the docs for data grid editing events, such as, I think,
itemEndEdit. -
Editable DataGrid and setInterval()
I have a page with an editable datagrid on it. I am not using
any item renderers or anything. Also I am refreshing this page
every five seconds by doing a setInterval() on it. Here's the
scenario which is causing the problem.
I select a cell to edit. The cell's look changes from regular
text to the look of an editable field. However if the refresh
happens before I make my changes, the cell gets converted back to
regular text. Is there a way for me to maintain the editability of
the cell through the refresh or should I use some other method of
refreshing the data?It seems to me that if the user has started entering data,
that you should suspend the refresh activity entirely, until the
current data is saved. Otherwise, it wll be nearly impossible to
update the data, since few people will be able to type and samve
sopmething in less than 5 seconds.
Tracy -
ErrorTemplate on editing datagrid
Hello,
I'm trying to create a MVVM application to register purchases.
I have ViewModel composed by :
Purchase
Products (return collection of products of the Purchase(Purchase.products)
ProductToAdd (this is a product to add to the Purchase via button)
Implement IDataErrorInfo to validate the order and the products collection
I created a collection of error to validate the ProductToAdd on button click.
So if there is an error on ProductToAdd the product is not add to the collection and the textbox with error become Red.
The value of each product of the purchase can be updated in the datagrid.
My problem is : When i update value in DataGrid the cell updated didn't get errorTemplate when is there an error.
My sample is the following : http://www.filedropper.com/validationexample_3
I didn't know how can i do 2 type of validation.
thanksThe Product class could implement the IEditableObject interface to keep track of whether it is currently in edit mode and then do the validation also in the setter if it is:
public class Product : IDataErrorInfo, INotifyPropertyChanged, IEditableObject
private string _Name = null;
[Required(ErrorMessage = "Nom is required")]
public string Name
get
return _Name;
set
_Name = value;
if (_isInEditMode) {
Validate();
RaisePropertyChanged("Name");
private int? _Quantity = null;
[Required(ErrorMessage = "Quantity is required")]
[Range(1, 9, ErrorMessage = "Quantity must be superior to 0 and inferior to 10")]
public int? Quantity
get
return _Quantity;
set
_Quantity = value;
if (_isInEditMode) {
Validate();
RaisePropertyChanged("Quantity");
public Dictionary<string, string> _errors = new Dictionary<string, string>();
public bool Validate()
_errors["Name"] = Validateurs.Courant.GetErreur(this, "Name");
_errors["Quantity"] = Validateurs.Courant.GetErreur(this, "Quantity");
RaisePropertyChanged("Name");
RaisePropertyChanged("Quantity");
if (_errors["Name"] != "" || _errors["Quantity"] != "")
return true;
return false;
#region INotifyPropertyChanged
public void RaisePropertyChanged(string propertyName)
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region IDataErrorInfo
public string Error
get
throw new NotImplementedException();
public string this[string columnName]
get
if (_errors.ContainsKey(columnName))
return _errors[columnName];
return null;
#endregion
#region IEditableObject Members
private bool _isInEditMode;
public void BeginEdit() {
_isInEditMode = true;
public void CancelEdit() {
_isInEditMode = false;
public void EndEdit() {
_isInEditMode = false;
#endregion
To remove the red exclamation mark that may get stuck in the row header even if you type in a valid value in the cell, you could use the following RowStyle:
<DataGrid Width="477" Height="200" Canvas.Left="10" Canvas.Top="157"
ItemsSource="{Binding products}" AutoGenerateColumns="False">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="ValidationErrorTemplate" Value="{x:Null}"/>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
Please refer to the following thread for more information about this:
http://stackoverflow.com/questions/5099039/wpf-datagrid-validation-errors-not-clearing
And remember to mark helpful posts as answer and to start a new thread if you have a new question. -
Datagrid vertical scrollbar problem
I wrote a search function for a datagrid component. The
dataprovider is a ArrayCollection variable. If the item is found in
the array, set the item to be selected in the datagrid. The problem
is when the selected item is at bottom of the datagrid, the
scrollbar doesn't refresh so I have to manually move the scrollbar
to see the selected item. Here is part of my code:
<mx:Script>
<![CDATA[
......(populate accountData using dataservice)
accountDS.fill(accountData);
private function findAccountById(id:String):void
var size:int = accountData.length - 1;
for(var i:int = 0; i< size; i++) {
var account:Object = accountData.getItemAt(i);
if(account.accountNumber.search(id) != -1)
dgAccount.selectedIndex = i;
break;
]]>
</mx:Script>
<mx:ArrayCollection id="accountData"/>
<mx:DataService id="accountDS"
destination="accountlist"/>
<mx:Panel >
<mx:DataGrid id="dgAccounts" dataProvider="{accountData}"
editable="false">
<mx:columns>
<mx:DataGridColumn dataField="accountNumber"/>
<mx:DataGridColumn dataField="accountType" />
</mx:columns>
</mx:DataGrid>
</mx:Panel>You need to look at the API for DataGrid. Particularly the
property "verticalScrollPosition".
The logic in your expectation that setting selectedIndex
should update the scroll position is flawed. What if you selected
an item with the mouse and then wanted to browse the other options?
You would use the scroll bar for this. Your selection might
disappear from the list but you would want it to stay selected.
Thus the scroll position and the selected index are completely
independent of one another.
The point I am trying to make is this: you are required to
set the verticalScrollPosition when you set selectedIndex if you
want them to work in concert.
Maybe you are looking for
-
How to schedule cross-client job?
Hi Experts, Now I'm running in client 001 and want to schedule a job which should run in client 002. I check the Function Module JOB_OPEN, JOB_SUBMIT, and JOB_CLOSE. There is no client-related parameter in the importing. Suppose the report name is AB
-
I'm runnign on Vista, and 3 days ago Ihave 83.4 GB Free space in my hard disk, and just an hour ago, I checked and it read 74 GB free in those three days I did not download any program or saved any file, and in a matter of 3 days i lost 9 Gb, so I de
-
I'm using VS 2012 and want to create an app that opens up a specific website, however I do not want the website window opened in the maximized state. What code can I use to manipulate the window size when it opens?
-
Hi, I have product and stores dimensions, some measures and a custom measure 'Obs'. One of the measures is 'Type', others are 'saling_price' and 'cost_price'. Now I have to run a model and every time a rule is not satisfied by one product/store, the
-
Hi, I am having two node in my RAC application running on window server 2003 and of oracle version 10.2.01 My first node is Ntptaibdb01 which is currently handling the production load. Issues is the server reboots itself not sure what may be the prob