0 Replies Latest reply on Feb 20, 2007 12:32 PM by DARAB

    Cell render breaks when grid is resorted

    DARAB
      I'm using a 4-button cell renderer in the Macromedia Devnet enhanced datagrid. I have column sorting turned on for many of the colunms. Cell rendering works fine until I click on a column title and resort the grid. When I select a radio button, the radio button I select appears not to be selected as soon as I move my cursor off of it. It doesn't matter which column I sort by or if it is sorted in ascending or descending order.

      If I resort the grid in its original order, the cell render works fine again and any radio button selected after resorting now appears selected, if though they did not appear to be selected after a resort.

      I have turned of the ability to resort the grid which has irritated my customers.

      I'm using Flash 8 and the latest Flash Player.

      Here is my cell renderer's code:

      import mx.core.UIComponent
      import mx.controls.RadioButton

      class CR_Progress_Statuses extends UIComponent
      {
      private var radioTotal:Number = 4;
      private var radioWidth:Number = 20;//55
      private var startX:Number = 67;
      private var deltaX:Number = 2;
      private var contentWidth:Number;

      private var radios:Array;

      var owner; // The row that contains this cell
      var listOwner : MovieClip; // the reference we receive to the list
      var getCellIndex : Function; // the function we receive from the list
      var getDataLabel : Function; // the function we receive from the list


      function RatingRadioRenderer()
      {
      }

      function init(Void):Void
      {
      super.init();
      contentWidth = 230;
      radios = new Array();
      }

      function createChildren(Void):Void
      {
      var groupName:String = "Status_rdogrp";
      var radio:RadioButton;

      radio = mx.controls.RadioButton(createObject("RadioButton", "Planned", 1));
      radio.label = "";
      radio.data = "1";
      radio.groupName = groupName;
      radio.labelPlacement = "left";
      radios.push(radio);

      radio = mx.controls.RadioButton(createObject("RadioButton", "Presented", 2));
      radio.label = "";
      radio.data = "2";
      radio.groupName = groupName;
      radio.labelPlacement = "left";
      radios.push(radio);

      radio = mx.controls.RadioButton(createObject("RadioButton", "Practiced", 3));
      radio.label = "";
      radio.data = "3";
      radio.groupName = groupName;
      radio.labelPlacement = "left";
      radios.push(radio);

      radio = mx.controls.RadioButton(createObject("RadioButton", "Mastered", 4));
      radio.label = "";
      radio.data = "4";
      radio.groupName = groupName;
      radio.labelPlacement = "left";
      radios.push(radio);

      // Listener sur le group pour prendre en compte
      // les touches (droite, gauche)
      var g = radio._parent[groupName];
      g.addEventListener("click", this);
      }

      function size(Void):Void
      {
      doLayout();
      }

      function doLayout(Void):Void
      {
      var w:Number = __width;
      var h:Number = __height;
      var x:Number = (__width - contentWidth) / 2;
      x += startX;

      // 12 : minimal value for radio height
      for (var i:Number = 0; i < radioTotal; i++)
      {
      var radio = radios ;
      // 12 : minimal value for radio height
      radio.setSize(radioWidth,h);
      radio._x = x;
      radio._y = (__height-12)/2;
      x += radioWidth+deltaX;
      }
      }

      function setValue(value:String, item:Object, sel:Boolean):Void
      {
      if (item == undefined)
      {
      for (var i:Number = 0; i < radioTotal; i++)
      {
      var radio = radios
      ;
      radio._visible = false;
      }
      return;
      }

      var selectedRadio = null;
      var noValue:Boolean = true;
      for (var i:Number = 0; i < radioTotal; i++)
      {
      var radio = radios ;
      radio._visible = true;

      if (radio.selected)
      {
      selectedRadio = radio;
      }

      if (radio.data == value)
      {
      if (!radio.selected)
      {
      radio.selected = true;
      }
      noValue = false;
      }

      }
      // Special case for null value (0)
      if (noValue && selectedRadio != null)
      {
      selectedRadio.selected = false;
      }
      }

      function getPreferredHeight(Void):Number
      {
      return 12;
      }

      function click(eventObj:Object):Void
      {
      var target = eventObj.target;
      listOwner.dataProvider.editField(getCellIndex().itemIndex, getDataLabel(), target.selectedData);

      // Select the row of the radio button selected.
      // listOwner.selectedIndex = getCellIndex().itemIndex;
      }
      }