0 Replies Latest reply on Jun 2, 2014 7:19 AM by nehavaidya

    Select all not working correctly for checkbox column in datagrid

    nehavaidya Level 1

      I have a data grid with a check box column used for selecting the items in the data gird for printing. I have added a 'Select All' button which adds all items in the data grid to am XML collection and refreshes the data grid data provider. I have implemented the onUpdate event for the the check box column where I verify if the given row is the XML collection for printing and according decide to check or un-check the checkbox for that row. This works perfectly fine if the number of rows the in data grid are even, but if the rows are odd in number, then the center row i.e. the (n + 1) / 2 th row remains unchecked. That item is available in the XML collection and if I try printing then it even gets printed, but it shows as un-checked on the UI. Moreover, if I just hover my mouse over the check box, it immediately updates and shows up as checked. I have noticed that the update event simply doesn't get raised for that row. Below is the my mxml and action script code. Please do let me know what I might be doing wrong.

       

      DataGrid with check box item renderer:

       

      <s:DataGrid id="itemDetailsDataGridForPrinting" width="100%" height="95%"

        alternatingRowColors="[#ffffff,#DDE8FE]"

        dataProvider="{itemListCurrentForPrint}" fontSize="11" requestedRowCount="4"

        skinClass="sg.com.irys.irysee.dataGridCustomSkin" textAlign="center">

       

        <s:columns>

        <s:ArrayList>

        <s:GridColumn width="100"

         headerRenderer="sg.com.irys.irysee.renderer.CustomDGHeaderRenderer"

         headerText="SR NO" labelFunction="GetSerialNo"></s:GridColumn>

        <s:GridColumn id="printTagGridColumn" visible="false" width="100"

         dataField="ownership__status"

         headerRenderer="sg.com.irys.irysee.renderer.CustomDGHeaderRenderer"

         headerText="PRINT">

        <s:itemRenderer>

        <fx:Component>

        <s:GridItemRenderer>

       

        <fx:Script>

        <![CDATA[

        import flash.net.navigateToURL;

       

        import mx.controls.Alert;

        public function onUpdateComplete(event:Event):void{  

        //Alert.show("Inside update complete: " + data.item__code);

        if(data!=null){                            

        if(outerDocument.itemsToPrintXmlCollection.contains(data)){                        

        event.currentTarget.selected=true;                    

        }else{                        

        event.currentTarget.selected=false;                 

        }               

        }            

        }

       

        protected function checkBoxSelectItemForUnMap_clickHandler(event:MouseEvent):void

        {

        if(checkBoxSelectItemForUnMap.selected == true) {

        data.ownership__status = true;

        if (!outerDocument.itemsToPrintXmlCollection.contains(data)){

        outerDocument.itemsToPrintXmlCollection.addItem(data);

        }

        }

        else

        if(checkBoxSelectItemForUnMap.selected == false) {

        data.ownership__status = false;

        if(outerDocument.itemsToPrintXmlCollection.contains(data)) {

        var i : int = outerDocument.itemsToPrintXmlCollection.getItemIndex(data);

        outerDocument.itemsToPrintXmlCollection.removeItemAt(i)

        }

        }

        }

       

        ]]>

        </fx:Script>

       

        <s:HGroup width="100%" height="100%" horizontalAlign="center"

         verticalAlign="middle">

       

        <s:CheckBox id="checkBoxSelectItemForUnMap"

        change="data.ownership__status = selected"

        click="checkBoxSelectItemForUnMap_clickHandler(event)"

        enabled="true"

        selected="{outerDocument.itemsToPrintXmlCollection.contains(data)}">

       

        </s:CheckBox>

        </s:HGroup>

        </s:GridItemRenderer>

        </fx:Component>

        </s:itemRenderer>

        </s:GridColumn>

        <s:GridColumn width="100" dataField="tagging__status"

         headerText="PRINT STATUS">

        </s:GridColumn>

        </s:ArrayList>

        </s:columns>

        </s:DataGrid>

       

      Select All function:

       

      protected function selectButton_clickHandler(event:MouseEvent):void

        {

        itemsToPrintXmlCollection.removeAll();

        itemsToPrintXmlCollection.addAll(itemDetailsDataGridForPrinting.dataProvider);

        var tempList : IList = itemDetailsDataGridForPrinting.dataProvider;

        itemDetailsDataGridForPrinting.dataProvider = new XMLListCollection();

        itemDetailsDataGridForPrinting.dataProvider = tempList;

        selectAll.enabled = false;

        clearAll.enabled = true;

        }

       

        protected function clearButton_clickHandler(event:MouseEvent):void

        {

        itemsToPrintXmlCollection.removeAll();

        var tempList : IList = itemDetailsDataGridForPrinting.dataProvider;

        itemDetailsDataGridForPrinting.dataProvider = new XMLListCollection();

        itemDetailsDataGridForPrinting.dataProvider = tempList;

        clearAll.enabled = false;

        selectAll.enabled = true;

        }

       

      OUTPUT:

       

      selectall_error.png