开发者

Flex AdvancedDataGrid c/p rows issue

I'm a newbie in Flex/AS3 development and I came across an issue that bugs me for a while now. I'm using an AdvancedDataGrid with some columns, and an ArrayCollection as the provider. I would like to make a copy/paste functionality so that multiple rows can be selected, copied, and then pasted below the selected (or last selected row).

The problem is when I copy the data from one row to another, both of those rows become highlighted on mouse-over (upper instance isn't even selectable) - just as in this topic: Flex DataGrid/DataProvider bug?

First I thought it was the issue of copying the reference, but it persist even if I use ObjectUtil.copy() method. Furthermore, I manually change one of the properties called "order" so that the objects of the ArrayCollection aren't identical, but it doesn't help. Dataprovider is called newTreatmentData, and the DataGrid is newTreatme开发者_运维知识库ntDG.

Any suggestions are more then welcome.

Here's part of the code that is relevant:

        private function getSelectedRow(event:Event):void
        {
            selectedRow = newTreatmentDG.selectedIndex;
        }
        private function copySelection(event:Event):void
        {
            bufferData = new ArrayCollection();
            var sortedIndices:Array = newTreatmentDG.selectedIndices.sort();
            for (var i:int = 0; i < newTreatmentDG.selectedIndices.length; i++){                        //copy selected rows to the buffer
                var j:int = sortedIndices[i];
                bufferData.addItem(newTreatmentData[j]);
            }
        }
        private function pasteSelection(event:Event):void
        {
            var rowsToMove:int = newTreatmentData.length - selectedRow - 1;                                 //number of rows to move after pasting

            for (var i:int = 1; i <= bufferData.length; i++){                                                   
                if (selectedRow + bufferData.length + i > newTreatmentData.length){                             // adding objects to the array collection to avoid range error
                    newTreatmentData.addItem(null);
                }
            }
                for (i = 1; i <= rowsToMove; i++){  
                newTreatmentData[selectedRow + bufferData.length + i] = ObjectUtil.copy(newTreatmentData[selectedRow + i])  //first move the rows to "give room" for pasting        
                newTreatmentData[selectedRow + bufferData.length + i].order = selectedRow + bufferData.length + i;          //manually changing the "order" property, but it doesn't help
            }
            for (var j:int = 1; j <= bufferData.length; j++){                                           //paste the data from the buffer
                newTreatmentData[selectedRow + j] = ObjectUtil.copy(bufferData[j-1])
                newTreatmentData[selectedRow + j].order = selectedRow + j;                              //again changing the order property
            }
            newTreatmentData.refresh();
        }


I solved it by changing the mx_internal_uid property of every object in the dataprovider ArrayCollection. It seems that AdvancedDataGrid checks it to see if rows are equal. I assumed (and you know what they say about assumptions) that an object's UID changes when you copy its value into another object (hence the U in UID ;) ).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜