Apache flex 如何使用flex中的复选框选择datagrid中的所有行或选定行
实际上,我需要使用复选框对datagrid中的行进行编码选择。然后,如果我选择一行,则该行将只打印。如果我没有选择任何行,则获取要打印的所有行。Plz帮助编写代码Apache flex 如何使用flex中的复选框选择datagrid中的所有行或选定行,apache-flex,datagrid,checkbox,flex4,flex4.5,Apache Flex,Datagrid,Checkbox,Flex4,Flex4.5,实际上,我需要使用复选框对datagrid中的行进行编码选择。然后,如果我选择一行,则该行将只打印。如果我没有选择任何行,则获取要打印的所有行。Plz帮助编写代码 <mx:DataGrid id="dg" dataProvider="{dp}" allowMultipleSelection="true" selectable="true" height="100%" width="100%" >
<mx:DataGrid id="dg" dataProvider="{dp}" allowMultipleSelection="true" selectable="true" height="100%" width="100%" >
<mx:columns>
<mx:DataGridColumn headerText="Select" dataField="Select" textAlign="center">
<mx:itemRenderer>
<fx:Component id="chkGrid">
<mx:CheckBox click="data.Select=!data.Select" selected="{data.Select}"/>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="Name" dataField="Nname"/>
<mx:DataGridColumn headerText="Metal Weight" dataField="metalwgt"/>
<mx:DataGridColumn headerText="Diamond Weight" dataField="diamondwgt"/>
<mx:DataGridColumn headerText="Metal Carat" dataField="carat"/>
<mx:DataGridColumn headerText="Price" dataField="price"/>
<mx:DataGridColumn headerText="ImagePath" dataField="imagePathTxt" visible="false"/>
</mx:columns>
</mx:DataGrid>
</s:VGroup>
</s:BorderContainer>
</s:VGroup>
</s:HGroup>
</s:BorderContainer>
假设
打印\u clickHandler
是打印按钮的单击处理程序。。这就是获取这些选定行的代码
protected function print_clickHandler():void
{
var PrintCollection:ArrayCollection = new ArrayCollection;
// The below code will get you the selected rows..
for each(var item:Object in dp)
{
if(item.hasOwnProperty("Select") && item.Select)
PrintCollection.addItem(item);
}
// PrintCollection is the selected rows collection which you need to print
// or the below code will also get you the selected rows.. Either of it will work
dp.filterFunction = function(item:Object):Boolean
{
return (item.hasOwnProperty("Select") && item.Select);
}
dp.refresh();
// dp is the selected rows collection which you need to print
}