0
votes

I am working with Flex4 mx:Datagrid, and trying to add rows dynamically.

In my datagrid there are n rows at a given time. The last row contains a text "Click to add row", i.e. when the user clicks on this cell, the cell becomes editable, and the user can add the data. Once he/she presses enter, a new row automatically gets added, with the last cell again containing the text "Click to add row". I have been able to manage this by updating the dataprovider of the datagrid on the "itemEditEnd" event.

The problem I am trying to resolve is the following: In general, when the user edits any cell in the column, and presses enter, the cell in the next row automatically becomes editable. However, since in my case, I am refreshing the dataprovider when the user presses enter, so the last item does not become editable. I tried the following workarounds, but none of them worked:

  1. calling "createItemEditor" after updateCompete event.
  2. defining a timer event in "itemEditEnd" function and calling "createItemEditor" after the timer completes.

I am sure I am doing some silly mistake here, but can't find it. Any help would be really appreciated.

Thanks, Kapil

2
Just to clarify: If the user hits Enter when adding a new record, you want it to refresh and have the last row not be editable. If the user hits Enter when editing an existing row, you want it to go to the next line and be editable, correct?Jason Towne

2 Answers

0
votes

I think he always to have the last row editable after creating a new one or editing a row. It seems you are not refreshing the index of the row to set editable.

0
votes

I found the solution to the problem. The issue was incorrect usage of "createItemEditor". It seems that the right way to do it is to use the "editedItemPosition". When this property is modified, it automatically dispatches the propertyChange event.

So, instead of using the "createItemEditor", when I set the following, then things work perfectly fine :)

divisionNamesGrid.editedItemPosition = {columnIndex: cIndex, rowIndex: rIndex};                              

Thanks, Kapil