2 Replies Latest reply on Dec 6, 2010 11:36 PM by qdechochen

    strange things using datagrid

    qdechochen

      I write a itemrender for a datagridcolumn like this.

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" paddingLeft="4" paddingRight="4" width="100%" height="100%" dataChange="doDataChange()">

      <mx:Script>

      <![CDATA[

      public var configNode:XML;

      private function doDataChange():void

      {

      if(configNode==null||configNode.children()==0)return;

      var fieldValue:String=this.data["Growth"];

      DoSel(fieldValue);

      }

       

       

      private function DoSel(sVal:String):void

      {

      var nodes:XMLList=configNode.children().(child("@Value")==sVal);

      if(nodes.length()>0)

      {

      var page:Object=this.parentDocument;

      var text:String=nodes[0].text();

      GrowthText.text=text;

      }

       

      this.Growth0.setStyle("backgroundColor",0xFFFFFF);

      this.Growth1.setStyle("backgroundColor",0xFFFFFF);

      this.Growth2.setStyle("backgroundColor",0xFFFFFF);

       

      if(sVal=="0")

      this.Growth0.setStyle("backgroundColor",0xCC0000);

      else if(sVal=="1")

      this.Growth1.setStyle("backgroundColor",0x0000CC);

      else if(sVal=="2")

      this.Growth2.setStyle("backgroundColor",0x00AA00);

       

      this.data.Growth=sVal;

      }

      ]]>

      </mx:Script>

      <mx:HBox id="Growth0" click="DoSel('0')" width="60" height="100%" borderColor="#BBBBBB" borderStyle="solid"/>

      <mx:HBox id="Growth1" click="DoSel('1')" width="60" height="100%" borderColor="#BBBBBB" borderStyle="solid"/>

      <mx:HBox id="Growth2" click="DoSel('2')" width="60" height="100%" borderColor="#BBBBBB" borderStyle="solid"/>

      <mx:Label id="GrowthText" width="80"/>

      </mx:HBox>

       

       

      This will show some graphics according to the value of "Growth", and I could change the value by clicking on the HBoxes(Growth0,Growth1,or Growth2).

       

      when i click the headtitle of Growth, the sorting works properly. But after I set values of Growth( by click on Growth0, or Growth1,or Growth2), and then click the Growth title, the sorting doesn't work. And what is more strange is that the rows become cluttered.

       

      This is the order before setting values and sorting.

      a.png

       

      If i set some more values( by clicking ), and the sorting by thhe 5th column, which is "生长情况", it shows me:

      b.png

      more repeated rows listed.

       

      Anyone knows how to solved that?

        • 1. Re: strange things using datagrid
          Flex harUI Adobe Employee

          Read the first item renderer post on my blog.  Renderers get recycled.

          You'll need to do things like unset growText.text if there is no configNode,

          etc.

           

          --

          Alex Harui

          Flex SDK Team

          Adobe System, Inc.

          http://blogs.adobe.com/aharui

          • 2. Re: strange things using datagrid
            qdechochen Level 1

            Thank you for your reply.

             

            but i don't think it the reason because configNode is always not null in my code. And I modified the code to reset the itemrender as you said, but problem still appeared.

             

            And what's more strange is sorting by  other columns won't caused any problems. Only sorting by Growth cause these strange things.

            I know that renders may get recycled, while that would only cause "Growth" no refreshing when rows change. It won't show me more rows.

            Thanks again. And do you have any other suggestions?