【问题标题】:how to select all rows or selected rows in datagrid using checkbox in flex如何使用flex中的复选框选择数据网格中的所有行或选定行
【发布时间】:2012-12-31 20:25:32
【问题描述】:

实际上我需要使用复选框编码选择数据网格中的行。然后,如果我选择一行,那一行只会打印。如果我没有选择行,请打印所有行。请帮助代码。

                    <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>

【问题讨论】:

    标签: apache-flex datagrid checkbox flex4 flex4.5


    【解决方案1】:

    假设print_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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-16
      • 2010-11-08
      • 1970-01-01
      • 2011-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多