hi,
also bei mir geht das so. entscheidend ist einfach, dass du schon einmal nach der spalte alter sortiert hast. die neuen personen werden dann ans richtige ort geaddet....
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication applicationComplete="init()" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.utils.ObjectUtil;
import mx.collections.ArrayCollection;
[Bindable]
private var persons : ArrayCollection;
private function init():void{
this.persons = new ArrayCollection();
this.persons.addItem( {name:"Hans",alter:12} );
this.persons.addItem( {name:"Hans",alter:15} );
this.persons.addItem( {name:"Hans",alter:17} );
this.persons.addItem( {name:"Paul",alter:12} );
this.persons.addItem( {name:"Paul",alter:15} );
this.persons.addItem( {name:"Paul",alter:17} );
this.persons.addItem( {name:"Peter",alter:12} );
this.persons.addItem( {name:"Peter",alter:15} );
this.persons.addItem( {name:"Peter",alter:17} );
}
private function compare(itemA:Object,itemB:Object):int{
var alterCompare : int = ObjectUtil.numericCompare( itemA.alter,itemB.alter);
return alterCompare;
}
private function compare1(itemA:Object,itemB:Object):int{
var compare : int = ObjectUtil.numericCompare( itemA.alter,itemB.alter);
if( compare == 0){
compare = ObjectUtil.stringCompare( itemA.name,itemB.name, true);
}
return compare;
}
private function addPerson():void{
this.persons.addItem({name:this.nameInput.text,alter:Number(this.alterInput.text)});
}
]]>
</mx:Script>
<mx:DataGrid dataProvider="{this.persons}" left = "10" right = "10" id = "uebersicht" height = "100%" bottom = "10" top = "84">
<mx:columns>
<mx:DataGridColumn headerText = "Name" dataField = "name"/>
<mx:DataGridColumn id="test" headerText = "" dataField = "alter" width = "40" sortCompareFunction="compare1" sortable="true" sortDescending="true"/>
</mx:columns>
</mx:DataGrid>
<mx:HBox y="26" left="10" right="10">
<mx:Button label="Add Person" click="addPerson()"/>
<mx:Label text="NAME"/>
<mx:TextInput id="nameInput"/>
<mx:Label text="ALTER"/>
<mx:TextInput id="alterInput"/>
</mx:HBox>
</mx:WindowedApplication>