Search code examples
actionscript-3apache-flexadvanceddatagrid

AdvancedDataGrid: row moves to the bottom of the ADG when editing a value


I have an AdvancedDataGrid with editable set true on some columns. If i edit one of the values in the ADG, the row moves to the bottom of the node/branch containing the items im currently editing.

My AdvancedDataGrid is defined in ActionScript3, and i use a grouping collection to group a flat dataProvider.

My problem is that i often want to edit several cells of one row, and if i edit one of the cells and then click somewhere else, the row moves to the bottom of the ADG. How can i avoid this? I want the row to stay selected and at the same index.


Solution

  • I guess i was a bit to quick to post this question, but maybe my mistake helps someone else. At the time of creating the editing, i didnt know about the itemUpdate(object) method of the ArrayCollection, so i removed the item, updated the item and then added it to the same index again(code below):

    ac.removeItemAt(i);
    ac.addItemAt(event.itemRenderer.data, i);
    

    This does not work together with the hierarchical data in the AdvancedDataGrid. Insead of beeing inserted back in the right index it is displayed at the bottom of the current branch in the ADG. The solution was very simple by using the following code, which works with the GroupingCollection:

    var field:String = event.dataField;
    var obj:Object = event.itemRenderer.data;
    //Update the field that was edited by the user
    obj[field] = editedValue;
    //update the object in the dataProvider
    ressursTavle.itemUpdated(obj);