I am using a AdvancedDatagrid with checkbox ItemRenderer.Its one field is a
number field so for that I have written a Custom Sort function.But the
problem comes when we sort that field and select the row through checkbox
which have same value for the number column.
the code is :
UserVO.as
package com.dgrigg.vo
{
/**
* Simple User value object
*/
public class UserVO
{
[Bindable]
public var name: String;
[Bindable]
public var email: String;
[Bindable]
public var online: Boolean = false;
[Bindable]
public var id:Number;
public function UserVO()
{
}
}
}
---------Application-------------------------
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="init();" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import com.dgrigg.vo.UserVO;
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
import mx.utils.ObjectUtil;
[Bindable]private var users: ArrayCollection
/* [Bindable]
private var users: ArrayCollection=new ArrayCollection([
{name:"alex",email:"[email protected]",id:"1"},
{name:"alex1",email:"[email protected]",id:"2"},
{name:"alex2",email:"[email protected]",id:"3"},
{name:"alex3",email:"[email protected]",id:"4"},
{name:"alex4",email:"[email protected]",id:"5"},
{name:"alex5",email:"[email protected]",id:"6"},
{name:"alex6",email:"[email protected]",id:"7"},
{name:"alex7",email:"[email protected]",id:"8"},
{name:"alex8",email:"[email protected]",id:"9"},
{name:"alex8",email:"[email protected]",id:"9"},
{name:"alex11",email:"[email protected]",id:"1"},
{name:"alex11",email:"[email protected]",id:"1"},
]); */
private function init():void
{
var user: UserVO;
users = new ArrayCollection();
users.addEventListener(CollectionEvent.COLLECTION_CHANGE,
handleDataProviderChange);
user = new UserVO();
user.name = 'alex';
user.email = '[email protected]';
user.id=1
users.addItem(user);
user = new UserVO();
user.name = 'bob';
user.email = '[email protected]';
user.id=1
users.addItem(user);
user = new UserVO();
user.name = 'charlie';
user.email = '[email protected]';
user.id=1
users.addItem(user);
user = new UserVO();
user.name = 'doug';
user.email = '[email protected]';
user.id=2
users.addItem(user);
user = new UserVO();
user.name = 'ed';
user.email = '[email protected]';
user.id=3
users.addItem(user);
user = new UserVO();
user.name = 'frank';
user.email = '[email protected]';
user.id=4
users.addItem(user);
user = new UserVO();
user.name = 'greg';
user.email = '[email protected]';
user.id=5
users.addItem(user);
user = new UserVO();
user.name = 'hector';
user.email = '[email protected]';
user.id=6
users.addItem(user);
user = new UserVO();
user.name = 'ivan';
user.email = '[email protected]';
users.addItem(user);
//users
}
private function
handleDataProviderChange(event:CollectionEvent):void
{
var len:int = users.length;
var online:int = 0;
for (var i:int=0;i<len;i++)
{
if (users.getItemAt(i).online)
{
online++;
}
}
trace_txt.text = 'Users online: ' + online;
}
public function
sortGridColumn(obj1:Object,obj2:Object):int
{
var fieldName:String="id";
var value1:Number = (obj1[fieldName] == '' ||
obj1[fieldName] == null) ? null : new Number(obj1[fieldName]);
var value2:Number = (obj2[fieldName] == '' ||
obj2[fieldName] == null) ? null : new Number(obj2[fieldName]);
return ObjectUtil.numericCompare(value1, value2);
}
]]>
</mx:Script>
<mx:VBox>
<mx:AdvancedDataGrid dataProvider="{users}" width="400"
sortExpertMode="true" >
<mx:columns>
<mx:AdvancedDataGridColumn headerText="Online"
sortable="false" dataField="online" editable="false">
<mx:itemRenderer>
<mx:Component>
<mx:CheckBox
click="data.online=!data.online" selected="{data.online}"/>
</mx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>
<mx:AdvancedDataGridColumn headerText="Email"
dataField="email"/>
<mx:AdvancedDataGridColumn headerText="Name"
dataField="name"/>
<mx:AdvancedDataGridColumn headerText="id"
dataField="id" sortCompareFunction="sortGridColumn"/>
</mx:columns>
</mx:AdvancedDataGrid>
<mx:TextArea id="trace_txt" width="400" height="20"/>
</mx:VBox>
</mx:Application>
Now in above code id in the number field and when we sort the column and we
select any row with its value 1 the row moves up and down.
How can we stop this?
--
View this message in context:
http://old.nabble.com/AdvancedDataGrid-with-custom-sort-and-Checkbox-ItemRenderer-not-working-properly-tp30607574p30607574.html
Sent from the Flex India mailing list archive at Nabble.com.
--
You received this message because you are subscribed to the Google Groups "Flex
India Community" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/flex_india?hl=en.