Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

actionscript 3 - DataGrid itemrenderer getting issue while scroll

I am using radio button inside spark datagrid as following way.

<s:DataGrid dataProvider="{arrList}" >
<s:columns>
<mx:ArrayList>
<mx:source>
    <s:GridColumn width="90" headerText="radio">
     <s:itemRenderer >
     <fx:Component>
        <s:GridItemRenderer>
                <fx:Script>
                <![CDATA[
                    override public function set data( value:Object ) : void 
                    {
                        super.data = value;
                        rdId.group=outerDocument.rbgGroup;
                    }
                ]]>
                </fx:Script>
          <s:RadioButton id="rdId" />
        </s:GridItemRenderer>
        </fx:Component>
        </s:itemRenderer>
    </s:GridColumn>

     <s:GridColumn headerText="Name" dataField="name" />
    </mx:source>
  </mx:ArrayList>
</s:columns>
</s:DataGrid>

I have created group for radiobutton as i want any one of selected.

<s:RadioButtonGroup id="rbgGroup" />

This working fine. But, if i select any radio like first and scroll then it will select another radio button automatically and first selected removed.

I have checked many other post like this but that doesn't seems work.

Issue occurred only when i scroll.
Any help would greatly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

More then likely this has to do with the virtual layout.

virtual and non-virtual:

The main difference between a virtual and non-virtual layout is how many renderers are created. A non-virtual layout creates a renderer for every item at startup, where virtual layouts only create renderers for items that are currently in view. This is a huge performance gain when you have dataProviders with thousands of items, but only a handful are shown at any given time. The spark Datagrid uses an layout that turns on virtual layout by default.

Unfortunately you cannot change this easily for Datagrids. A common solution is to store the selection state in the data and on the set data you already are overriding also set the selection state based on the data.

Per request in the comment a code sample:

 <s:GridItemRenderer>
     <fx:Script>
          <![CDATA[
                override public function set data( value:Object ) : void 
                {
                    super.data = value;
                    rdId.group=outerDocument.rbgGroup;

                    //just like you are setting the group, mark it as selected based on the data. 
                    //Update your data when it becomes selected.
                    rdId.selected = value.selected;
                }

                protected function rb_clickHandler(event:Event):void {
                    data.selected = rbId.selected;
                }
            ]]>
            </fx:Script>
      <s:RadioButton id="rdId" change="rdId_clickHandler(event)"/>
    </s:GridItemRenderer>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...