0 Replies Latest reply on Dec 22, 2011 12:56 AM by amol bhandwale

    enable disable linkbar links in datagrid itemrenderer.

    amol bhandwale Level 1

      Hi All,

       

      I have to show the linkbar in datagrid column as a renderer and enable and disable the links according to attached documents codes.

      here are my sample code

       

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

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">

       

      <mx:Script>

          <![CDATA[

              import mx.collections.ArrayCollection;

       

              [Bindable]

                public var arrColl:ArrayCollection = new ArrayCollection();

                public function init():void{

       

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                    arrColl.addItem(["1,2,3","1,2"]);

                    arrColl.addItem(["1,2,3", "1,3"]);

                }

          ]]>

      </mx:Script>

          <mx:DataGrid id="dg" dataProvider="{arrColl}" width="200" height="500" x="510" y="168" >

              <mx:columns>

                  <mx:DataGridColumn  itemRenderer="assets.components.linkbarItemRenderer"  />   

              </mx:columns>

          </mx:DataGrid>

       

      </mx:Application>

       

      My item renderer linkbarItemRenderer.mxml as

       

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

      <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" creationComplete="init();" >

      <mx:Script>

          <![CDATA[

              import mx.controls.LinkButton;

              import mx.collections.ArrayCollection;

       

              import mx.controls.Alert;

              [Bindable] public var arrColl : ArrayCollection = new ArrayCollection();

              public var arrDocType : ArrayCollection = new ArrayCollection([{data:"1" , label:"AP"},{data:"2" , label:"AR"},{data:"3" , label:"BOL"}]);

              public var attDoccodes : Array;

              public function init():void

              {

                  try

                  {   

                      var requiredDoc :String = data[0];

                      var attachDoc : String = data[1];

       

                      var reqDocCodes :Array =  requiredDoc.split(",");

                      attDoccodes = attachDoc.split(",");

                      if(reqDocCodes != null)

                      {

                          //add the links of required documents.

                          for(var i:int = 0 ; i<reqDocCodes.length; i++ )

                          {

                              var obj:Object = new Object();

                              for(var j : int = 0; j < arrDocType.length; j++)

                              {

                                  if(arrDocType.getItemAt(j).data == reqDocCodes[i])

                                  {

                                      obj.label = arrDocType.getItemAt(j).label;

                                      obj.data  = reqDocCodes[i];

                                  }   

                              }

                              arrColl.addItem(obj);

                          }

                      }

                      callLater(enableDisalbeLinks);

                  }

                  catch(error:Error)

                  {

                      Alert.show("error ::"+error.getStackTrace());

                  }

              } 

       

              public function enableDisalbeLinks():void

              {

                  try

                  {

                      //disable all links first

                      for(var q:int=0; q< arrColl.length; q++)

                      {

                          LinkButton(linkBarId.getChildAt(q)).enabled = false;   

                      }

       

                      if(attDoccodes != null)

                      {

                          for(var k:int = 0; k<attDoccodes.length; k++)

                          {

                              for(var l:int = 0 ; l<arrColl.length; l++)

                              {

                                  if(arrColl.getItemAt(l).data == attDoccodes[k])

                                  {

                                      LinkButton(linkBarId.getChildAt(l)).enabled = true;   

                                  }

                              }

                          }

                      }

       

                  }

                  catch(error:Error)

                  {

                      Alert.show("error ::"+error.getStackTrace());

                  }

              }   

       

          ]]>

      </mx:Script>

       

              <mx:LinkBar id="linkBarId" dataProvider="{arrColl}" />   

      </mx:HBox>

       

      It renderes the link in correct form in datagrid first time.when i scroll the datagrid the rows are miss up with each other and links are not shown propers in enable/disable format.

       

       

      Thanks,

      Amol.