2 Replies Latest reply on Sep 16, 2009 9:39 AM by rfkrocktk

    Removing data items from DataGroup

    rfkrocktk Level 1

      I need to remove data items from a Spark DataGroup on an action of one of the items. My itemrenderer for that DataGroup (which extends the Spark ItemRenderer class) has a button within it that is more or less a "delete" or "remove" button. The desired functionality is to click the button and remove that item from the DataGroup. Unfortunately, I can't find a way to access the dataProvider of the DataGroup from within my ItemRenderer. Am I missing something? I'm building from

        • 1. Re: Removing data items from DataGroup
          Shongrunden Adobe Employee

          You can reach the DataGroup from a renderer via the parent property.


          Here is a quick code sample that should do what you are looking for:


                  <s:layout><s:VerticalLayout /></s:layout>
                          <fx:String>item 0</fx:String>
                          <fx:String>item 1</fx:String>
                          <fx:String>item 2</fx:String>
                          <fx:String>item 3</fx:String>
                          <fx:String>item 4</fx:String>
                                  <s:State name="normal" />
                                  <s:State name="hovered" />
                                      import spark.components.DataGroup;
                                      public function deleteItem():void {
                                          var parentDataGroup:DataGroup = parent as DataGroup;
                                          // remove the item
                                          parentDataGroup.dataProvider.removeItemAt(parentDataGroup.dataProvider.getItemIndex(data) )
                              <s:Button label="Delete {data}" click="deleteItem()" />                       
          • 2. Re: Removing data items from DataGroup
            rfkrocktk Level 1

            Thanks, I think that totally solves my problem