flex DataGrid 标题上放 CheckBox 实现全选
1个回答
2013-07-18
展开全部
这个很简单
利用headerRenderer加入checkbox然后这个checkbox调用外部方法实现全选.
附送代码片段,如有不懂可以追问.
<mx:DataGridColumn headerText=" " width="20">
<mx:headerRenderer>
<mx:Component>
<mx:VBox horizontalAlign="center">
<mx:CheckBox id="chball" selected="{outerDocument.ISsel}" change="outerDocument.selectAll(this)" creationComplete="outerDocument.setObjChb(this)"/>
</mx:VBox>
</mx:Component>
</mx:headerRenderer>
<mx:itemRenderer>
<mx:Component>
<mx:VBox width="100%" horizontalAlign="center">
<mx:CheckBox id="cbox" selected="{int(data.chk)}" selectedField="{int(data.chk)}" click="outerDocument.checkClick(this)"/>
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
//调用的外部方法
public function selectAll(obj:Object):void
{
ISsel=!ISsel;
if (dataArray.length > 0)
{
if (obj.chball.selected == true)
{
for (var i:int=0; i < dataArray.length; i++)
{
dataArray[i].chk=1;
}
for(var i:int = 0; i < dataArray.length;i++){
if(dataArray[i].chk == 1){
//绑定被选中的数据
arr.addItem(dataArray[i]);
}
}
aa.text = "已选择"+dataArray.length+"名";
}else{
for (var j:int=0; j < dataArray.length; j++)
{
dataArray[j].chk=0;
}
aa.text = "已选择"+0+"名";
arr.removeAll();
}
dataArray.refresh();
}
}
public function setObjChb(obj:Object):void
{
this.objChb=obj;
}
利用headerRenderer加入checkbox然后这个checkbox调用外部方法实现全选.
附送代码片段,如有不懂可以追问.
<mx:DataGridColumn headerText=" " width="20">
<mx:headerRenderer>
<mx:Component>
<mx:VBox horizontalAlign="center">
<mx:CheckBox id="chball" selected="{outerDocument.ISsel}" change="outerDocument.selectAll(this)" creationComplete="outerDocument.setObjChb(this)"/>
</mx:VBox>
</mx:Component>
</mx:headerRenderer>
<mx:itemRenderer>
<mx:Component>
<mx:VBox width="100%" horizontalAlign="center">
<mx:CheckBox id="cbox" selected="{int(data.chk)}" selectedField="{int(data.chk)}" click="outerDocument.checkClick(this)"/>
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
//调用的外部方法
public function selectAll(obj:Object):void
{
ISsel=!ISsel;
if (dataArray.length > 0)
{
if (obj.chball.selected == true)
{
for (var i:int=0; i < dataArray.length; i++)
{
dataArray[i].chk=1;
}
for(var i:int = 0; i < dataArray.length;i++){
if(dataArray[i].chk == 1){
//绑定被选中的数据
arr.addItem(dataArray[i]);
}
}
aa.text = "已选择"+dataArray.length+"名";
}else{
for (var j:int=0; j < dataArray.length; j++)
{
dataArray[j].chk=0;
}
aa.text = "已选择"+0+"名";
arr.removeAll();
}
dataArray.refresh();
}
}
public function setObjChb(obj:Object):void
{
this.objChb=obj;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询